Skip to content

Commit 160f90f

Browse files
committed
Merge branch '2.11'
2 parents ee8ce17 + 2088a49 commit 160f90f

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Project: jackson-databind
2222
#2522: `DeserializationContext.handleMissingInstantiator()` throws `MismatchedInputException`
2323
for non-static inner classes
2424
#2525: Incorrect `JsonStreamContext` for `TokenBuffer` and `TreeTraversingParser`
25+
#2555: Use `@JsonProperty(index)` for sorting properties on serialization
2526
- Add `SerializerProvider.findContentValueSerializer()` methods
2627
2728
2.10.2 (not yet released)

src/test/java/com/fasterxml/jackson/databind/ser/TestSerializationOrder.java renamed to src/test/java/com/fasterxml/jackson/databind/ser/SerializationOrderTest.java

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Unit tests for verifying that constraints on ordering of serialized
99
* properties are held.
1010
*/
11-
public class TestSerializationOrder
11+
public class SerializationOrderTest
1212
extends BaseMapTest
1313
{
1414
static class BeanWithCreator
@@ -68,7 +68,7 @@ static class BeanFor459 {
6868

6969
// For [databind#311]
7070
@JsonPropertyOrder(alphabetic = true)
71-
public class BeanForGH311 {
71+
static class BeanForGH311 {
7272
private final int a;
7373
private final int b;
7474

@@ -82,6 +82,21 @@ public BeanForGH311(@JsonProperty("b") int b, @JsonProperty("a") int a) { //b an
8282
public int getB() { return b; }
8383
}
8484

85+
// We'll expect ordering of "FUBAR"
86+
@JsonPropertyOrder({ "f" })
87+
static class OrderingByIndexBean {
88+
public int r;
89+
public int a;
90+
91+
@JsonProperty(index = 1)
92+
public int b;
93+
94+
@JsonProperty(index = 0)
95+
public int u;
96+
97+
public int f;
98+
}
99+
85100
/*
86101
/*********************************************
87102
/* Unit tests
@@ -90,19 +105,23 @@ public BeanForGH311(@JsonProperty("b") int b, @JsonProperty("a") int a) { //b an
90105

91106
private final ObjectMapper MAPPER = newJsonMapper();
92107

93-
public void testImplicitOrderByCreator() throws Exception
94-
{
95-
assertEquals("{\"c\":1,\"a\":2,\"b\":0}", MAPPER.writeValueAsString(new BeanWithCreator(1, 2)));
108+
private final ObjectMapper ALPHA_MAPPER = jsonMapperBuilder()
109+
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
110+
.build();
111+
112+
public void testImplicitOrderByCreator() throws Exception {
113+
assertEquals("{\"c\":1,\"a\":2,\"b\":0}",
114+
MAPPER.writeValueAsString(new BeanWithCreator(1, 2)));
96115
}
97116

98-
public void testExplicitOrder() throws Exception
99-
{
100-
assertEquals("{\"c\":3,\"a\":1,\"b\":2,\"d\":4}", MAPPER.writeValueAsString(new BeanWithOrder(1, 2, 3, 4)));
117+
public void testExplicitOrder() throws Exception {
118+
assertEquals("{\"c\":3,\"a\":1,\"b\":2,\"d\":4}",
119+
MAPPER.writeValueAsString(new BeanWithOrder(1, 2, 3, 4)));
101120
}
102121

103-
public void testAlphabeticOrder() throws Exception
104-
{
105-
assertEquals("{\"d\":4,\"a\":1,\"b\":2,\"c\":3}", MAPPER.writeValueAsString(new SubBeanWithOrder(1, 2, 3, 4)));
122+
public void testAlphabeticOrder() throws Exception {
123+
assertEquals("{\"d\":4,\"a\":1,\"b\":2,\"c\":3}",
124+
MAPPER.writeValueAsString(new SubBeanWithOrder(1, 2, 3, 4)));
106125
}
107126

108127
public void testOrderWithMixins() throws Exception
@@ -122,20 +141,23 @@ public void testOrderWrt268() throws Exception
122141

123142
public void testOrderWithFeature() throws Exception
124143
{
125-
ObjectMapper mapper = jsonMapperBuilder()
126-
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
127-
.build();
128144
assertEquals("{\"a\":1,\"b\":2,\"c\":3,\"d\":4}",
129-
mapper.writeValueAsString(new BeanFor459()));
145+
ALPHA_MAPPER.writeValueAsString(new BeanFor459()));
130146
}
131147

132148
// [databind#311]
133149
public void testAlphaAndCreatorOrdering() throws Exception
134150
{
135-
ObjectMapper mapper = jsonMapperBuilder()
136-
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
137-
.build();
138-
String json = mapper.writeValueAsString(new BeanForGH311(2, 1));
151+
String json = ALPHA_MAPPER.writeValueAsString(new BeanForGH311(2, 1));
139152
assertEquals("{\"a\":1,\"b\":2}", json);
140153
}
154+
155+
// [databind#2555]
156+
public void testOrderByIndexEtc() throws Exception
157+
{
158+
// since "default" order can actually vary with later JDKs, only verify
159+
// case of alphabetic-as-default
160+
assertEquals(aposToQuotes("{'f':0,'u':0,'b':0,'a':0,'r':0}"),
161+
ALPHA_MAPPER.writeValueAsString(new OrderingByIndexBean()));
162+
}
141163
}

0 commit comments

Comments
 (0)