-
-
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
MapperFeature.SORT_PROPERTIES_ALPHABETICALLY is not respected for records #3900
Comments
Fix/workaroundDisable
ExplanationPreviously, Records deserialization is specially handled, resulting in some behavioural differences (mostly missing behaviours) compared to POJO deserialization.
...behaves similarly to:
...resulting in this issue. I'm really sorry about the inconvenience this caused you. Reminds me of an adage that one does not simply fix a bug - some "bugs" may be relied on as features. 😬 |
oh no, @yihtserns 👍🏻 It's already good you feel responsible. I don't think you should be sorry because, the change thoroughly discussed (I really did read most part). I could have written more tests against record types. |
As unfortunate as unplanned behavior changes are, I will consider this "works as intended", so that one needs to disable:
to force sorting of all properties. |
@cowtowncoder Can you consider disabling SORT_CREATOR_PROPERTIES_FIRST by default by any chance? I think the fact that enabling one single SORT_PROPERTIES_ALPHABETICALLY feature doesn't automatically work for all the properties is not quite expected behavior. Not sure how many people would use SORT_PROPERTIES_ALPHABETICALLY with SORT_CREATOR_PROPERTIES_FIRST set as the default. Just for the context, my use case is testing. I compare generated JSON documents with data files stored in a canonical form sorting properties and map entries. |
I cannot disagree... 👀 In fact, from a user's perspective,
Maybe you can file an issue regarding suggestion, @agavrilov76 ? |
the problem with disabling SORT_CREATOR_PROPERTIES_FIRST is that putting creator properties first is more performant for deserialization. since all creator properties are required to create the instance, all properties before the last creator property in the input need to be buffered. SORT_CREATOR_PROPERTIES_FIRST ensures that there is as little buffering as possible. |
This is quite informant... putting a side the changing of default configuration, let's add this to the JavaDoc itself. |
As per @yawkat's pointing it out, there are non-trivial performance implications. |
I just saw that if neither SORT_CREATOR_PROPERTIES_FIRST or SORT_PROPERTIES_ALPHABETICALLY is set, jackson will still put creator properties first. So it may be safe to disable SORT_CREATOR_PROPERTIES_FIRST by default since SORT_PROPERTIES_ALPHABETICALLY is also off by default, so with default settings the output would be unchanged. |
Ok but what is the specific upside of doing that? Would it make enabling |
MapperFeature.SORT_PROPERTIES_ALPHABETICALLY
is no longer respected by record method based JSON propertiesVersion information
2.15
To Reproduce
Output:
The property 'a' in the example below comes at the last place:
Expected behavior
All record properties must be serialized the natural order
The text was updated successfully, but these errors were encountered: