-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Enum handling parity with Jackson #818
Conversation
...port/src/main/java/io/micronaut/serde/support/deserializers/collect/EnumMapDeserializer.java
Outdated
Show resolved
Hide resolved
...port/src/main/java/io/micronaut/serde/support/deserializers/collect/EnumMapDeserializer.java
Show resolved
Hide resolved
|
||
@NonNull | ||
private E transform(@NonNull Decoder decoder, Object value) throws IOException { | ||
for (EnumBeanIntrospection.EnumConstant<? super E> enumConstant : enumIntrospection.getConstants()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you precalculate some of this stuff? Maybe create a map instead of interesting on every deserialization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added pre-calculation in 9d4e089
|
||
@Override | ||
public void serialize(@NonNull Encoder encoder, @NonNull EncoderContext context, @NonNull Argument<? extends E> type, E value) throws IOException { | ||
for (EnumBeanIntrospection.EnumConstant<? extends E> enumConstant : enumIntrospection.getConstants()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to precalculate constants as a map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added pre-calculation in 9d4e089
public E deserialize(@NonNull Decoder decoder, @NonNull DecoderContext context, @NonNull Argument<? super E> type) throws IOException { | ||
var value = decoder.decodeString(); | ||
|
||
for (EnumBeanIntrospection.EnumConstant<? super E> enumConstant : enumIntrospection.getConstants()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, please try to precalculate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added pre-calculation in 9d4e089
Please fix checkstyle |
I have refactored caching a bit, please check. |
I think, need add test, when you use @Serdeable
enum MyEnum {
VALUE1("value_1"),
VALUE2("value_2"),
VALUE3("value_3");
private final String value;
MyEnum(String value) {
this.value = value;
}
@JsonValue
public String getValue() {
return value;
}
} |
oh, It already exists. Then everything looks good to me |
Thanks @oujesky ! |
Improve Enum handling parity with Jackson (#818)
Improve Enum handling parity with Jackson (#818)
Improve enum serialization and deserialization to move closer to parity with Jackson
Additional Jackson annotations support:
@JsonValue
@JsonProperty
Improved
EnumSet
de/serialization of contained enumsAdded support for
EnumMap