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

Make PropertyNamingStrategy not affect Enums #4414

Merged
merged 5 commits into from
Mar 7, 2024

Conversation

JooHyukKim
Copy link
Member

possible fix for #4409

@cowtowncoder
Copy link
Member

cowtowncoder commented Mar 4, 2024

There are a few issues here; I don't think this would work.

First question is compatibility: do we know when did PropertyNamingStrategy start applying to Enums (I know it's indirect and not explicit change, i.e. side effect)? If it was 2.16 we could I guess consider 2.16 patch -- but if 2.15, it definitely would need to wait until 2.17.

Second: determination for renaming should be based on type being introspected; PR does checks on per-property basis but it should really be based on type of POJO that POJOPropertiesCollector is introspecting. So check needs to be earlier before loop.
But it looks like there are some concerns (failing/regressed test I assume) wrt @JsonFormat(shape = Shape.OBJECT) applied on Enum type, or perhaps even property.
Not 100% sure how that is to be tackled, but it cannot really be checked from within place check is now.

private boolean _shouldRename(POJOPropertyBuilder prop) {
// [databind#4409]: Need to skip renaming for Enums, unless OBJECT format
if (getType().isEnumType() && Objects.equals(prop.getPrimaryType(), getType())) {
if (prop.isObjectFormatShape()) {
Copy link
Member

Choose a reason for hiding this comment

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

This is in wrong place: it would check for annotation of a property of Enum type referring to another type and being annotated as Shape.OBJECT -- that would not cover cases where Enum class is annotated or -- if supported, not sure it is -- property of another (almost certainly non-Enum) type pointing Enum type and having Shape override.

@cowtowncoder
Copy link
Member

How about this: a more extensive change to block any application of global PropertyNamingStrategy for enums; adding test with specific Enum entries that would be affected -- and merging that test in 2.15 to show before/after change?

@JooHyukKim
Copy link
Member Author

JooHyukKim commented Mar 6, 2024

How about this: a more extensive change to block any application of global PropertyNamingStrategy for enums;

Makes sense 👍🏼 Could you share with me if you already have any idea on how to approach things?

adding test with specific Enum entries that would be affected -- and merging that test in 2.15 to show before/after change?

You mean like test I wrote in PR against 2.15 in my personal repo? I can't think of other cases at the moment, but will figure out.

Btw, should we keep the work against 2.16 then?
cc. @cowtowncoder

@JooHyukKim
Copy link
Member Author

Implemented 20b6e54 as per comment #4403 /cc @cowtowncoder

@JooHyukKim JooHyukKim marked this pull request as ready for review March 6, 2024 10:56
Copy link
Member

@cowtowncoder cowtowncoder left a comment

Choose a reason for hiding this comment

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

LGTM, will try to get merged later tonight.

@cowtowncoder cowtowncoder merged commit 83e0bd8 into FasterXML:2.16 Mar 7, 2024
5 checks passed
@JooHyukKim JooHyukKim deleted the fix-4409 branch March 8, 2024 00:33
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