Skip to content

Fix #5152: support "iPhone" style properties -- add MapperFeature.FIX_FIELD_NAME_CASE_MISMATCH #5187

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

Open
wants to merge 6 commits into
base: 2.x
Choose a base branch
from

Conversation

cowtowncoder
Copy link
Member

@cowtowncoder cowtowncoder commented Jun 11, 2025

Fixes #5152: adds a new MapperFeature.

@cowtowncoder cowtowncoder changed the title (WIP) Fix #5152: support "iPhone" style properties Fix #5152: support "iPhone" style properties Jun 11, 2025
@cowtowncoder
Copy link
Member Author

Initial implementation complete; need to consider naming still, at least.

@cowtowncoder cowtowncoder marked this pull request as ready for review June 11, 2025 18:35
@cowtowncoder cowtowncoder changed the title Fix #5152: support "iPhone" style properties Fix #5152: support "iPhone" style properties -- add MapperFeature.FIX_FIELD_NAME_CASE_MISMATCH Jun 11, 2025
@cowtowncoder cowtowncoder added most-wanted Tag to indicate that there is heavy user +1'ing action 2.20 Issues planned at 2.20 or later labels Jun 11, 2025
@cowtowncoder
Copy link
Member Author

@JooHyukKim WDYT? Naming of MapperFeature hard but implementation seems straight-forward enough.

* <p>
* Feature is disabled by default for backwards compatibility.
* Feature is disabled by default in 2.x for backwards-compatibility.
* It will be enabled by default in 3.0.
Copy link
Member

Choose a reason for hiding this comment

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

enabled in 3.0 ? Let's add documentation label then

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, need a follow-up issue for defaults changing after this gets merged.

@cowtowncoder cowtowncoder added the 3.0-release-notes Issues relevant for 3.0 release notes. label Jun 12, 2025
*/
ALLOW_IS_GETTERS_FOR_NON_BOOLEAN(false),
FIX_FIELD_NAME_CASE_MISMATCH(false),
Copy link
Member

Choose a reason for hiding this comment

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

My concern is... Would the name imply we would fix any case difference issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really. So maybe should still consider name to use...

In a way it is not necessarily limited to first two, but it only checks cases where Field name has first and/or second character upper case. Since those are ones where name-mangling can produce differences. But comparison itself consider whole implicit names.
So bit tricky to explain.

Alternatively could change logic itself to actually consider all cases of "lone" (unmatched) Fields, either with at least one upper-case letter, or possibly just any (since Getter/Setter name could have upper-case even without Field)

@@ -132,7 +145,6 @@ public void testKBSBroadCastingStyleProperty() throws Exception {
assertEquals("{\"KBSBroadCasting\":\"Korean Broadcasting System\"}", serialized);
}

@JacksonTestFailureExpected
Copy link
Member

Choose a reason for hiding this comment

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

If we make this test case valid then we may want to change JavaDoc for our new feature because it says first or second character are only supported

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it's... bit tricky to explain logic. Basically only cases where name-mangling should produce mismatches are if name starts with one or more upper-case (non-lower case) letters -- like "KBSBroadcasting" -- or starts with lower-case but is immediately followed by one or more upper-case letters -- like "iPhone". But in either case, it can be a sequence of more than one upper-case letters that need to be considered in case-insensitive manner.

So logic is:

  1. Check if and only if:
    • Field name has first and/or second letter upper-case; and that name does not yet match any other accessor
  2. If checking, see if Field name matches, case excluded to ANY other accessor sets (that do not have Field matched)
  3. If check matches, combine Field and non-Field accessors, using Field name as-is (not mangled getter/setter name)

switch (name.length()) {
case 0:
return false;
default:
Copy link
Member

Choose a reason for hiding this comment

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

Is this neccessary to place default statement in the middle?

Unless strongly required, Could switch to if else statement

Copy link
Member Author

Choose a reason for hiding this comment

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

Could move 0 as last, making default first entry. Not sure if that's any better.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah not a blocker. We can go on

@JooHyukKim
Copy link
Member

Even though this might be subjective , just one concern regarding the feature name. Having keywords like UPPER_CASE or PREFIX would narrow the scope.

@cowtowncoder other than the feature name, implementation looks reasonable already. Sorry, late reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.20 Issues planned at 2.20 or later 3.0-release-notes Issues relevant for 3.0 release notes. most-wanted Tag to indicate that there is heavy user +1'ing action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support "iPhone" style capitalized properties (add MapperFeature.FIX_FIELD_NAME_CASE_MISMATCH)
2 participants