Skip to content

Conversation

@JacksonJang
Copy link
Contributor

I just added the anyGetterSortingBeforeFields test for issue #518 to document the expected sorting behavior between any-getter properties and regular fields.

@cowtowncoder
Copy link
Member

cowtowncoder commented Dec 5, 2025

Do we document this behavior somewhere? (ordering)

My understanding is that it is the exactly opposite and that "any-getter" properties are (and should) come last, after regular properties (Field or Getter-based ones).

@JacksonJang
Copy link
Contributor Author

Ah, I see, I misunderstood this part.
I assumed that when @JsonPropertyOrder(alphabetic = true) is declared on AnyGetterBeforeFieldsBean,
all properties including the @JsonAnyGetter entries would be merged and sorted purely alphabetically.
That’s why I originally wrote the test that way.

Based on your explanation, my understanding now is that regular properties should come first and @JsonAnyGetter properties should come after them, with alphabetical ordering applied within each group.

So for a bean with both @JsonPropertyOrder(alphabetic = true) and @JsonAnyGetter, the expected JSON would be:
assertEquals(a2q("{'x':1,'y':2,'a':3,'b':4}"), json);

Does this match the intended it?

@JacksonJang JacksonJang closed this Dec 5, 2025
@cowtowncoder
Copy link
Member

cowtowncoder commented Dec 5, 2025

Almost: except no sorting is done for any properties. That is, ordering of any properties is undefined, no guarantees -- in practice, output in iteration order of underlying Map, but that's an implementation detail.

But any properties should come after regular ones. I'll add this to Javadocs.

@JacksonJang
Copy link
Contributor Author

Thank you for the clarification!

So, to summarize, is it correct to understand that when alphabetic = true, the any properties are not sorted?

Regarding issue #518, since it can be handled with the following configuration:

@JsonPropertyOrder({ "id", "unwrapped", "name", "any" })

would it be acceptable to remove the old test that relied on the previous behavior?

@cowtowncoder
Copy link
Member

Correct: as in, any properties are not sorted (aside from being written after regular properties by default; or recently as a block (wrt #518 or #4388 )

And yes, good point on updating AnyGetterSorting518Test. Can update, move from under tofix.

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