Skip to content

Commit

Permalink
Change MapperFeature.SORT_PROPERTIES_ALPHABETICALLY default to true…
Browse files Browse the repository at this point in the history
… (3.x) (#4572)
  • Loading branch information
JooHyukKim authored Jun 15, 2024
1 parent 928292e commit 4b6c307
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Versions: 3.x (for earlier see VERSION-2.x)
(contributed by Joo-Hyuk K)
#4567: Enable `SerializationFeature.WRITE_ENUMS_USING_TO_STRING` by default (3.0)
(contributed by Joo-Hyuk K)
#4572: Change `MapperFeature.SORT_PROPERTIES_ALPHABETICALLY` default to true
(contributed by Joo-Hyuk K)
- Remove `MappingJsonFactory`
- Add context parameter for `TypeSerializer` contextualization (`forProperty()`)
- Default for `JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES` changed to `false` for 3.0
6 changes: 3 additions & 3 deletions src/main/java/tools/jackson/databind/MapperFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum MapperFeature
* precedence than setters, so they are only used if no
* setter is found for the Map/Collection property.
*<p>
* Feature is disabled by default since 3.0 (with 2.x was enabled)
* Feature is disabled by default since 3.0 (in 2.x was enabled)
*/
USE_GETTERS_AS_SETTERS(false),

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

/**
* Feature that defines whether Creator properties (ones passed through
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CreatorTestObject(
public void testPlain() throws Exception
{
String result = OBJECT_MAPPER.writeValueAsString(new PlainTestObject("test", 1));
assertEquals("{\"strField\":\"test\",\"intField\":1}", result);
assertEquals("{\"intField\":1,\"strField\":\"test\"}", result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void testDeserializeUsingCanonicalConstructor_WhenJsonPropertyConstructor
} catch (DatabindException e) {
verifyException(e, "Unrecognized property \"id\"");
verifyException(e, "RecordWithTwoJsonPropertyWithoutJsonCreator");
verifyException(e, "2 known properties: \"the_id\", \"the_email\"");
verifyException(e, "2 known properties: \"the_email\", \"the_id\"");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public record Record4085(int total, @JsonView(View4085Field.class) int current)
public void testRecordWithView4085() throws Exception
{
final Record4085 input = new Record4085(1, 2);
final String EXP = a2q("{'total':1,'current':2}");
final String EXP = a2q("{'current':2,'total':1}");
final ObjectWriter w = newJsonMapper().writer();

// by default, all properties included, without view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,16 @@ static class DefaultShape3271 extends Shape3271 {}
private static final String fruitListJson = "[" + pinguoJson + "," + mandarinJson + "]";

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

private static final Camry camry = new Camry("Sweet Ride", "candy-apple-red");
private static final String camryJson = "{\"name\":\"Sweet Ride\",\"exteriorColor\":\"candy-apple-red\",\"type\":\"camry\"}";
private static final String camryJson = "{\"exteriorColor\":\"candy-apple-red\",\"name\":\"Sweet Ride\",\"type\":\"camry\"}";
private static final Accord accord = new Accord("Road Rage", 6);
private static final String accordJson = "{\"name\":\"Road Rage\",\"speakerCount\":6,\"type\":\"accord\"}";
private static final CarWrapper camryWrapper = new CarWrapper(camry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
MAPPER.writeValueAsString(new BeanWithCreator(1, 2)));
}

Expand Down

0 comments on commit 4b6c307

Please sign in to comment.