Skip to content

Commit 4b6c307

Browse files
authored
Change MapperFeature.SORT_PROPERTIES_ALPHABETICALLY default to true (3.x) (#4572)
1 parent 928292e commit 4b6c307

File tree

8 files changed

+14
-12
lines changed

8 files changed

+14
-12
lines changed

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Versions: 3.x (for earlier see VERSION-2.x)
6262
(contributed by Joo-Hyuk K)
6363
#4567: Enable `SerializationFeature.WRITE_ENUMS_USING_TO_STRING` by default (3.0)
6464
(contributed by Joo-Hyuk K)
65+
#4572: Change `MapperFeature.SORT_PROPERTIES_ALPHABETICALLY` default to true
66+
(contributed by Joo-Hyuk K)
6567
- Remove `MappingJsonFactory`
6668
- Add context parameter for `TypeSerializer` contextualization (`forProperty()`)
6769
- Default for `JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES` changed to `false` for 3.0

src/main/java/tools/jackson/databind/MapperFeature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public enum MapperFeature
4040
* precedence than setters, so they are only used if no
4141
* setter is found for the Map/Collection property.
4242
*<p>
43-
* Feature is disabled by default since 3.0 (with 2.x was enabled)
43+
* Feature is disabled by default since 3.0 (in 2.x was enabled)
4444
*/
4545
USE_GETTERS_AS_SETTERS(false),
4646

@@ -278,9 +278,9 @@ public enum MapperFeature
278278
* Note: does <b>not</b> apply to {@link java.util.Map} serialization (since
279279
* entries are not considered Bean/POJO properties.
280280
*<p>
281-
* Feature is disabled by default.
281+
* Feature is enabled by default since 3.0 (in 2.x was disabled)
282282
*/
283-
SORT_PROPERTIES_ALPHABETICALLY(false),
283+
SORT_PROPERTIES_ALPHABETICALLY(true),
284284

285285
/**
286286
* Feature that defines whether Creator properties (ones passed through

src/test-jdk17/java/tools/jackson/databind/records/RecordCreatorSerialization4452Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public CreatorTestObject(
4343
public void testPlain() throws Exception
4444
{
4545
String result = OBJECT_MAPPER.writeValueAsString(new PlainTestObject("test", 1));
46-
assertEquals("{\"strField\":\"test\",\"intField\":1}", result);
46+
assertEquals("{\"intField\":1,\"strField\":\"test\"}", result);
4747
}
4848

4949
@Test

src/test-jdk17/java/tools/jackson/databind/records/RecordExplicitCreatorsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void testDeserializeUsingCanonicalConstructor_WhenJsonPropertyConstructor
153153
} catch (DatabindException e) {
154154
verifyException(e, "Unrecognized property \"id\"");
155155
verifyException(e, "RecordWithTwoJsonPropertyWithoutJsonCreator");
156-
verifyException(e, "2 known properties: \"the_id\", \"the_email\"");
156+
verifyException(e, "2 known properties: \"the_email\", \"the_id\"");
157157
}
158158
}
159159

src/test-jdk17/java/tools/jackson/databind/records/RecordSerializationOrderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void testSerializationOrder() throws Exception {
3939
NestedRecordTwo nestedRecordTwo = new NestedRecordTwo("2", "111110");
4040
NestedRecordOne nestedRecordOne = new NestedRecordOne("1", "[email protected]", nestedRecordTwo);
4141
final String output = MAPPER.writeValueAsString(nestedRecordOne);
42-
final String expected = "{\"id\":\"1\",\"email\":\"[email protected]\",\"nestedRecordTwo\":{\"id\":\"2\",\"passport\":\"111110\"}}";
42+
final String expected = "{\"email\":\"[email protected]\",\"id\":\"1\",\"nestedRecordTwo\":{\"id\":\"2\",\"passport\":\"111110\"}}";
4343
assertEquals(expected, output);
4444
}
4545

@@ -49,7 +49,7 @@ public void testSerializationOrderWithJsonProperty() throws Exception {
4949
NestedRecordOneWithJsonProperty nestedRecordOne =
5050
new NestedRecordOneWithJsonProperty("1", "[email protected]", nestedRecordTwo);
5151
final String output = MAPPER.writeValueAsString(nestedRecordOne);
52-
final String expected = "{\"id\":\"1\",\"email\":\"[email protected]\",\"nestedProperty\":{\"id\":\"2\",\"passport\":\"111110\"}}";
52+
final String expected = "{\"email\":\"[email protected]\",\"id\":\"1\",\"nestedProperty\":{\"id\":\"2\",\"passport\":\"111110\"}}";
5353
assertEquals(expected, output);
5454
}
5555

src/test-jdk17/java/tools/jackson/databind/records/RecordWithView4085Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public record Record4085(int total, @JsonView(View4085Field.class) int current)
2222
public void testRecordWithView4085() throws Exception
2323
{
2424
final Record4085 input = new Record4085(1, 2);
25-
final String EXP = a2q("{'total':1,'current':2}");
25+
final String EXP = a2q("{'current':2,'total':1}");
2626
final ObjectWriter w = newJsonMapper().writer();
2727

2828
// by default, all properties included, without view

src/test/java/tools/jackson/databind/jsontype/ExistingPropertyTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,16 @@ static class DefaultShape3271 extends Shape3271 {}
267267
private static final String fruitListJson = "[" + pinguoJson + "," + mandarinJson + "]";
268268

269269
private static final Cat beelzebub = new Cat("Beelzebub", "tabby");
270-
private static final String beelzebubJson = "{\"name\":\"Beelzebub\",\"furColor\":\"tabby\",\"type\":\"kitty\"}";
270+
private static final String beelzebubJson = "{\"furColor\":\"tabby\",\"name\":\"Beelzebub\",\"type\":\"kitty\"}";
271271
private static final Dog rover = new Dog("Rover", 42);
272-
private static final String roverJson = "{\"name\":\"Rover\",\"boneCount\":42,\"type\":\"doggie\"}";
272+
private static final String roverJson = "{\"boneCount\":42,\"name\":\"Rover\",\"type\":\"doggie\"}";
273273
private static final AnimalWrapper beelzebubWrapper = new AnimalWrapper(beelzebub);
274274
private static final String beelzebubWrapperJson = "{\"animal\":" + beelzebubJson + "}";
275275
private static final List<Animal> animalList = Arrays.asList(beelzebub, rover);
276276
private static final String animalListJson = "[" + beelzebubJson + "," + roverJson + "]";
277277

278278
private static final Camry camry = new Camry("Sweet Ride", "candy-apple-red");
279-
private static final String camryJson = "{\"name\":\"Sweet Ride\",\"exteriorColor\":\"candy-apple-red\",\"type\":\"camry\"}";
279+
private static final String camryJson = "{\"exteriorColor\":\"candy-apple-red\",\"name\":\"Sweet Ride\",\"type\":\"camry\"}";
280280
private static final Accord accord = new Accord("Road Rage", 6);
281281
private static final String accordJson = "{\"name\":\"Road Rage\",\"speakerCount\":6,\"type\":\"accord\"}";
282282
private static final CarWrapper camryWrapper = new CarWrapper(camry);

src/test/java/tools/jackson/databind/ser/SerializationOrderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public BeanForStrictOrdering(@JsonProperty("c") int c, @JsonProperty("a") int a)
150150

151151
@Test
152152
public void testImplicitOrderByCreator() throws Exception {
153-
assertEquals("{\"c\":1,\"a\":2,\"b\":0}",
153+
assertEquals("{\"a\":2,\"c\":1,\"b\":0}",
154154
MAPPER.writeValueAsString(new BeanWithCreator(1, 2)));
155155
}
156156

0 commit comments

Comments
 (0)