-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Change MapperFeature.SORT_PROPERTIES_ALPHABETICALLY
default to true (3.x)
#4572
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
Changes from 2 commits
f879990
8995e93
354820b
c0e7cea
bd055ce
b9044bd
2d3f4a8
c66d2fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ public void testSerializationOrder() throws Exception { | |
NestedRecordTwo nestedRecordTwo = new NestedRecordTwo("2", "111110"); | ||
NestedRecordOne nestedRecordOne = new NestedRecordOne("1", "[email protected]", nestedRecordTwo); | ||
final String output = MAPPER.writeValueAsString(nestedRecordOne); | ||
final String expected = "{\"id\":\"1\",\"email\":\"[email protected]\",\"nestedRecordTwo\":{\"id\":\"2\",\"passport\":\"111110\"}}"; | ||
final String expected = "{\"email\":\"[email protected]\",\"id\":\"1\",\"nestedRecordTwo\":{\"id\":\"2\",\"passport\":\"111110\"}}"; | ||
assertEquals(expected, output); | ||
} | ||
|
||
|
@@ -49,7 +49,7 @@ public void testSerializationOrderWithJsonProperty() throws Exception { | |
NestedRecordOneWithJsonProperty nestedRecordOne = | ||
new NestedRecordOneWithJsonProperty("1", "[email protected]", nestedRecordTwo); | ||
final String output = MAPPER.writeValueAsString(nestedRecordOne); | ||
final String expected = "{\"id\":\"1\",\"email\":\"[email protected]\",\"nestedProperty\":{\"id\":\"2\",\"passport\":\"111110\"}}"; | ||
final String expected = "{\"email\":\"[email protected]\",\"id\":\"1\",\"nestedProperty\":{\"id\":\"2\",\"passport\":\"111110\"}}"; | ||
assertEquals(expected, output); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,7 +150,7 @@ public BeanForStrictOrdering(@JsonProperty("c") int c, @JsonProperty("a") int a) | |
|
||
@Test | ||
public void testImplicitOrderByCreator() throws Exception { | ||
assertEquals("{\"c\":1,\"a\":2,\"b\":0}", | ||
assertEquals("{\"a\":2,\"c\":1,\"b\":0}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, this seems wrong: since Constructor is:
order should remain "c", "a" (creator parameters), "b", given that So something is wrong... not sure if same is true for 2.x. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohhhhh. No, actually, I am wrong. Code in
that is, ALL Creator properties should be sorted before all non-Creator properties (unless explicit order dictates otherwise). So in that sense this works as expected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However: this brings up another question, mentioned elsewhere: should ordering of Record properties be ordered by declaration order because it:
I think I better file a separate issue for that; not strictly related to this PR, but something worth considering. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't had time to look at the sorting functionality wrt creator-properties yet, but my first intuition was wondering...
But it seems like Thank you for the explanation tho @cowtowncoder ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, Records are handled quite similar to POJOs with 2.18, in that their Constructors are selected either from explicit annotation, or, if none, by selection so-called "Canonical" constructor (one that has all record fields in order). But ordering of properties is then done separately across set of properties, not considering Creator (constructor or factory method). I think sorting is handled by I hope 2.18 code, esp. in |
||
MAPPER.writeValueAsString(new BeanWithCreator(1, 2))); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.