Skip to content
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
wants to merge 5 commits into from

Conversation

JooHyukKim
Copy link
Member

@JooHyukKim JooHyukKim commented Jan 11, 2024

Summary

This PR completes #4311 fix.
This PR fixes behavior introduced by #4311, when Enum is used as field of other class and POJOPropertiesCollector tries to rename it via _renameUsing(), we just drop the field.

Notes

@JooHyukKim JooHyukKim changed the title Write reproduction Put back enum field without renaming Jan 11, 2024
Comment on lines +1132 to +1135
if (!prop.hasSetter()
&& Objects.nonNull(prop.getField())
&& (Objects.equals(_type, prop.getField().getType()) && prop.getPrimaryType().isEnumType())
) {
Copy link
Member Author

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)

Copy link
Member

@cowtowncoder cowtowncoder Jan 11, 2024

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.

Copy link
Member

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.

Comment on lines +107 to +111
// 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);
Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

@cowtowncoder
Copy link
Member

Solved via #4314, will close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants