diff --git a/release-notes/VERSION b/release-notes/VERSION index 4f3d3bbfa7..d66b241dfc 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -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 diff --git a/src/main/java/tools/jackson/databind/MapperFeature.java b/src/main/java/tools/jackson/databind/MapperFeature.java index ac2503393c..b71972b073 100644 --- a/src/main/java/tools/jackson/databind/MapperFeature.java +++ b/src/main/java/tools/jackson/databind/MapperFeature.java @@ -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. *
- * 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), @@ -278,9 +278,9 @@ public enum MapperFeature * Note: does not apply to {@link java.util.Map} serialization (since * entries are not considered Bean/POJO properties. *
- * 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
diff --git a/src/test-jdk17/java/tools/jackson/databind/records/RecordCreatorSerialization4452Test.java b/src/test-jdk17/java/tools/jackson/databind/records/RecordCreatorSerialization4452Test.java
index 57b2310c48..3f39fc332c 100644
--- a/src/test-jdk17/java/tools/jackson/databind/records/RecordCreatorSerialization4452Test.java
+++ b/src/test-jdk17/java/tools/jackson/databind/records/RecordCreatorSerialization4452Test.java
@@ -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
diff --git a/src/test-jdk17/java/tools/jackson/databind/records/RecordExplicitCreatorsTest.java b/src/test-jdk17/java/tools/jackson/databind/records/RecordExplicitCreatorsTest.java
index 1f176ccfb4..d2ed7e577e 100644
--- a/src/test-jdk17/java/tools/jackson/databind/records/RecordExplicitCreatorsTest.java
+++ b/src/test-jdk17/java/tools/jackson/databind/records/RecordExplicitCreatorsTest.java
@@ -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\"");
}
}
diff --git a/src/test-jdk17/java/tools/jackson/databind/records/RecordSerializationOrderTest.java b/src/test-jdk17/java/tools/jackson/databind/records/RecordSerializationOrderTest.java
index ae75d294a4..6361928864 100644
--- a/src/test-jdk17/java/tools/jackson/databind/records/RecordSerializationOrderTest.java
+++ b/src/test-jdk17/java/tools/jackson/databind/records/RecordSerializationOrderTest.java
@@ -39,7 +39,7 @@ public void testSerializationOrder() throws Exception {
NestedRecordTwo nestedRecordTwo = new NestedRecordTwo("2", "111110");
NestedRecordOne nestedRecordOne = new NestedRecordOne("1", "test@records.com", nestedRecordTwo);
final String output = MAPPER.writeValueAsString(nestedRecordOne);
- final String expected = "{\"id\":\"1\",\"email\":\"test@records.com\",\"nestedRecordTwo\":{\"id\":\"2\",\"passport\":\"111110\"}}";
+ final String expected = "{\"email\":\"test@records.com\",\"id\":\"1\",\"nestedRecordTwo\":{\"id\":\"2\",\"passport\":\"111110\"}}";
assertEquals(expected, output);
}
@@ -49,7 +49,7 @@ public void testSerializationOrderWithJsonProperty() throws Exception {
NestedRecordOneWithJsonProperty nestedRecordOne =
new NestedRecordOneWithJsonProperty("1", "test@records.com", nestedRecordTwo);
final String output = MAPPER.writeValueAsString(nestedRecordOne);
- final String expected = "{\"id\":\"1\",\"email\":\"test@records.com\",\"nestedProperty\":{\"id\":\"2\",\"passport\":\"111110\"}}";
+ final String expected = "{\"email\":\"test@records.com\",\"id\":\"1\",\"nestedProperty\":{\"id\":\"2\",\"passport\":\"111110\"}}";
assertEquals(expected, output);
}
diff --git a/src/test-jdk17/java/tools/jackson/databind/records/RecordWithView4085Test.java b/src/test-jdk17/java/tools/jackson/databind/records/RecordWithView4085Test.java
index 252f11481c..85615a1704 100644
--- a/src/test-jdk17/java/tools/jackson/databind/records/RecordWithView4085Test.java
+++ b/src/test-jdk17/java/tools/jackson/databind/records/RecordWithView4085Test.java
@@ -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
diff --git a/src/test/java/tools/jackson/databind/jsontype/ExistingPropertyTest.java b/src/test/java/tools/jackson/databind/jsontype/ExistingPropertyTest.java
index c69aff469c..7c680dcf07 100644
--- a/src/test/java/tools/jackson/databind/jsontype/ExistingPropertyTest.java
+++ b/src/test/java/tools/jackson/databind/jsontype/ExistingPropertyTest.java
@@ -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