-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Put back enum field without renaming #4313
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import static com.fasterxml.jackson.databind.BaseMapTest.jsonMapperBuilder; | ||
import static com.fasterxml.jackson.databind.BaseTest.a2q; | ||
import static com.fasterxml.jackson.databind.BaseTest.q; | ||
|
||
// [databind#4302] | ||
|
@@ -52,10 +53,24 @@ public void setCat(String cat) { | |
} | ||
} | ||
|
||
enum AsField4302Enum { | ||
APPLE_SUGAR, | ||
SOME_PERSON; | ||
} | ||
|
||
static class AsField4302Bean { | ||
public AsField4302Enum someEnum = AsField4302Enum.APPLE_SUGAR; | ||
public String otherProp = "someOtherField"; | ||
} | ||
|
||
private final ObjectMapper MAPPER = jsonMapperBuilder() | ||
.propertyNamingStrategy(PropertyNamingStrategies.LOWER_CASE) | ||
.build(); | ||
|
||
private final ObjectMapper SNAKE_MAPPER = jsonMapperBuilder() | ||
.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE) | ||
.build(); | ||
|
||
@Test | ||
void testShouldWork() throws Exception | ||
{ | ||
|
@@ -78,5 +93,22 @@ void testShouldWork() throws Exception | |
assertEquals(q("CAT"), | ||
MAPPER.writeValueAsString(Setter4302Enum.CAT)); | ||
} | ||
|
||
@Test | ||
void testDeserializeSuccessfulUnaffectedField() throws Exception | ||
{ | ||
AsField4302Bean bean = new AsField4302Bean(); | ||
|
||
// test serialization | ||
assertEquals( | ||
a2q("{'some_enum':'APPLE_SUGAR','other_prop':'someOtherField'}"), | ||
SNAKE_MAPPER.writeValueAsString(bean)); | ||
|
||
// test deserialization | ||
AsField4302Bean result = SNAKE_MAPPER.readValue( | ||
a2q("{'some_enum':'SOME_PERSON', 'other_prop':'thisField'}"), AsField4302Bean.class); | ||
assertEquals(AsField4302Enum.SOME_PERSON, result.someEnum); | ||
assertEquals("thisField", result.otherProp); | ||
Comment on lines
+107
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test corresponds to the failing test in ion module --when there is Enum field, we should keep renaming it, same as before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. |
||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wonder if there is cleaner solution for this... 🤔
Or just extract method to some where (probably not
POJOPropertyBuilder
, it doens't need to know about Enum stuff)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.
Sorry, I should have noticed -- original "fix" is actually totally wrong.
It applies to properties with Enum value but what we want are properties WITHIN type that has properties.
I am not sure how it would have resolved the problem but I can look into fixing the problem. Odd databind had no test for naming strategy with Enum-valued POJO property.
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.
First thing I think (beyond revert) is to add a test for naming strategy. I can do that.