Skip to content

Commit

Permalink
Merge branch '2.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 28, 2019
2 parents ee8ce17 + 2088a49 commit 160f90f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Project: jackson-databind
#2522: `DeserializationContext.handleMissingInstantiator()` throws `MismatchedInputException`
for non-static inner classes
#2525: Incorrect `JsonStreamContext` for `TokenBuffer` and `TreeTraversingParser`
#2555: Use `@JsonProperty(index)` for sorting properties on serialization
- Add `SerializerProvider.findContentValueSerializer()` methods
2.10.2 (not yet released)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Unit tests for verifying that constraints on ordering of serialized
* properties are held.
*/
public class TestSerializationOrder
public class SerializationOrderTest
extends BaseMapTest
{
static class BeanWithCreator
Expand Down Expand Up @@ -68,7 +68,7 @@ static class BeanFor459 {

// For [databind#311]
@JsonPropertyOrder(alphabetic = true)
public class BeanForGH311 {
static class BeanForGH311 {
private final int a;
private final int b;

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

// We'll expect ordering of "FUBAR"
@JsonPropertyOrder({ "f" })
static class OrderingByIndexBean {
public int r;
public int a;

@JsonProperty(index = 1)
public int b;

@JsonProperty(index = 0)
public int u;

public int f;
}

/*
/*********************************************
/* Unit tests
Expand All @@ -90,19 +105,23 @@ public BeanForGH311(@JsonProperty("b") int b, @JsonProperty("a") int a) { //b an

private final ObjectMapper MAPPER = newJsonMapper();

public void testImplicitOrderByCreator() throws Exception
{
assertEquals("{\"c\":1,\"a\":2,\"b\":0}", MAPPER.writeValueAsString(new BeanWithCreator(1, 2)));
private final ObjectMapper ALPHA_MAPPER = jsonMapperBuilder()
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
.build();

public void testImplicitOrderByCreator() throws Exception {
assertEquals("{\"c\":1,\"a\":2,\"b\":0}",
MAPPER.writeValueAsString(new BeanWithCreator(1, 2)));
}

public void testExplicitOrder() throws Exception
{
assertEquals("{\"c\":3,\"a\":1,\"b\":2,\"d\":4}", MAPPER.writeValueAsString(new BeanWithOrder(1, 2, 3, 4)));
public void testExplicitOrder() throws Exception {
assertEquals("{\"c\":3,\"a\":1,\"b\":2,\"d\":4}",
MAPPER.writeValueAsString(new BeanWithOrder(1, 2, 3, 4)));
}

public void testAlphabeticOrder() throws Exception
{
assertEquals("{\"d\":4,\"a\":1,\"b\":2,\"c\":3}", MAPPER.writeValueAsString(new SubBeanWithOrder(1, 2, 3, 4)));
public void testAlphabeticOrder() throws Exception {
assertEquals("{\"d\":4,\"a\":1,\"b\":2,\"c\":3}",
MAPPER.writeValueAsString(new SubBeanWithOrder(1, 2, 3, 4)));
}

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

public void testOrderWithFeature() throws Exception
{
ObjectMapper mapper = jsonMapperBuilder()
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
.build();
assertEquals("{\"a\":1,\"b\":2,\"c\":3,\"d\":4}",
mapper.writeValueAsString(new BeanFor459()));
ALPHA_MAPPER.writeValueAsString(new BeanFor459()));
}

// [databind#311]
public void testAlphaAndCreatorOrdering() throws Exception
{
ObjectMapper mapper = jsonMapperBuilder()
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
.build();
String json = mapper.writeValueAsString(new BeanForGH311(2, 1));
String json = ALPHA_MAPPER.writeValueAsString(new BeanForGH311(2, 1));
assertEquals("{\"a\":1,\"b\":2}", json);
}

// [databind#2555]
public void testOrderByIndexEtc() throws Exception
{
// since "default" order can actually vary with later JDKs, only verify
// case of alphabetic-as-default
assertEquals(aposToQuotes("{'f':0,'u':0,'b':0,'a':0,'r':0}"),
ALPHA_MAPPER.writeValueAsString(new OrderingByIndexBean()));
}
}

0 comments on commit 160f90f

Please sign in to comment.