-
-
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
Add MapperFeature.SORT_CREATOR_PROPERTIES_BY_DECLARATION_ORDER
to use Creator properties' declaration order for sorting
#4580
Comments
Can we label this Regarding the mentioned 2 possibilities, would it be possible to support (and feasible to implement) both, if both of them are default behavior in 2.x? |
I don't think it absolutely has to be 3.x, although if it turns out difficult to do, or controversial, can consider 3.x only. |
Okay, I took some time on thinking. My ideas are... First, let's not introduce Second, no need to proactively resolve this issue. I would say let's just wait and see, until we have enough opinions. We don't have many requests/issues regarding current issue (except #3900). This is not enough to come up with best usage cases going further 2.18 or 3.x. |
I guess that's fair enough. I agree that we don't want too many on/off features, where number of combinations grows rapidly. So let's keep this open and see if we come up with better ideas; but not work on this before having clearer idea of what should be achieved (and with what configuration). |
For 3, I definitely want to have Java Records, Scala Case Classes and Kotlin equivalent default to using the defined order in the constructor (creator). It's a pity that MapperFeature.SORT_PROPERTIES_ALPHABETICALLY is a boolean. Could we deprecate it and in Jackson 3, we can add a new config option that allows multiple values.
|
Yes, on/off features are tricky. Unfortunately they are also very convenient to add -- adding But I like the idea of a smaller set of consistent options. I guess one possibility would be to define a handler interface (BeanPropertySorter?) that is configurable. I suspect that for 2.x we may still want to go with another I guess alternatively we could add abstraction even in 2.x but make it be built from Given that there is no -- I think -- change in behavior for 2.18, I think I'll tag this for 2.19 for now. To indicate we hope to tackle it after 2.18, unless someone has time and itch to do it sooner (can always change labels, it's just intent not commitment). |
If we are keeping MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, can we change its result then to mean to only affect properties that are not part of the creator properties. The creator properties come first. Can I also ask about whether we support specifically a locale for the sort? Alphabetic sort order is locale specific. https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/text/Collator.html |
If I remember correctly, we just use whatever As to changing EDIT: existing names of features do begin with |
MapperFeature.SORT_CREATOR_PROPERTIES_BY_DECLARATION_ORDER
to use Creator properties' declaration order for sorting
Ok. I think that for 2.x, addition of It seems to me there are 3 sensible property sorting choices -- and then 4th one we currently have for 3.0:
So: 2.x default is (3), 3.0 default is (4), as of now. But I would prefer (2) as default for 2.0, and I think this would also allow dropping of 2.x-only |
Describe your Issue
Although Creator-provided properties are sorted before other properties, esp. if
MapperFeature.SORT_CREATOR_PROPERTIES_FIRST
is enabled.But if
MapperFeature.SORT_PROPERTIES_ALPHABETICALLY
is enabled, properties of single Creator are still sorted alphabetically. This is probably not what is wanted, at least for Records.So, we have 2 possibilities:
SORT_CREATOR_PROPERTIES_FIRST
is enabled, retain order of all Properties-based Creators (unless there is explicit@JsonPropertyOrder
)Record
CreatorsFurther we could add a new
MapperFeature
to control above cases.Something like
MapperFeature.RETAIN_ORDER_OF_CREATOR_PROPERTIES
?NOTE: this becomes more obvious with 3.0 when
SORT_PROPERTIES_ALPHABETICALLY
will be enabled by default.The text was updated successfully, but these errors were encountered: