-
Notifications
You must be signed in to change notification settings - Fork 202
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
Add jsonValue check on Enum deserializer, default to checking name() function of enum #5103
Conversation
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.
Which enums are supporting upper case presently? Those should be updated with @JsonCreator
and we should move away from having these inconsistencies.
Supporting this will allow the inconsistencies to grow, whereas we should be working to remove them.
Signed-off-by: Taylor Gray <[email protected]>
…function of enum Signed-off-by: Taylor Gray <[email protected]>
final DeserializationContext deserializationContext = mock(DeserializationContext.class); | ||
when(jsonParser.getCodec()).thenReturn(objectMapper); | ||
|
||
when(objectMapper.readTree(jsonParser)).thenReturn(new TextNode(testEnumOption.toString())); |
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.
I think this should return using .name()
instead of .toString()
.
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.
No because in this case the value that users have to pass to the config is lowercase, not the enum value. Passing enum.name() will lead to exceptions since the JsonCreator returns the lowercase value
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.
This testing is using the TestEnumOnlyUppercase
enum. This does not have a @JsonCreator
.
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.
Ah I see
Enum<?> result = objectUnderTest.deserialize(jsonParser, deserializationContext); | ||
|
||
assertThat(result, equalTo(testEnumOption)); | ||
} |
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.
We may also benefit from a test where the enum has a toString()
which returns a different value, but is not marked with @JsonValue
. In this case, we should be using the enum's name()
. So we can verify this situation.
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.
Isn't that already covered with this test void enum_class_without_json_creator_or_json_value_annotation_returns_expected_enum_constant
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.
For that test, toString()
returns the name, so you can't be sure if the code is using name() or toString().
Can you change that enum's toString()
to return a random UUID?
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.
Sure will make that change
Signed-off-by: Taylor Gray <[email protected]>
… name() function of enum (opensearch-project#5103)" This reverts commit 9065acb.
… name() function of enum (opensearch-project#5103)" This reverts commit 9065acb.
… name() function of enum (opensearch-project#5103)" This reverts commit 9065acb. Signed-off-by: Taylor Gray <[email protected]>
Description
The new EnumDeserializer defaults to checking for the lower case enum value when there is no
@JsonCreator
on the enum class, and this broke basic enums likeSince we don't have consistency in enums as lower case we have to default to checking both for lowercase and uppercase values.
New behavior for deserializing enums
Issues Resolved
Resolves #[Issue number to be closed when this PR is merged]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.