Skip to content

Commit

Permalink
Mark #754 as fixed (actual fix bit earlier, same as #3045 presumably)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 21, 2021
1 parent dc62d3b commit 6b20100
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 49 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,11 @@ SunYiJun (xiaosunzhu@github)
having namingStrategy
(2.12.1)
Vassil Dichev (vdichev@github)
* Reported #754: EXTERNAL_PROPERTY does not work well with `@JsonCreator` and
`FAIL_ON_UNKNOWN_PROPERTIES`
(2.12.2)
Miguel G (Migwel@github)
* Reported, contributed fix for #3025: UntypedObjectDeserializer` mixes multiple unwrapped
collections (related to #2733)
Expand Down
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Project: jackson-databind

2.12.2 (not yet released)

#754: EXTERNAL_PROPERTY does not work well with `@JsonCreator` and
`FAIL_ON_UNKNOWN_PROPERTIES`
(reported by Vassil D)
#3008: String property deserializes null as "null" for
`JsonTypeInfo.As.EXTERNAL_PROPERTY`
#3022: Property ignorals cause `BeanDeserializer `to forget how to read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@

public class ExternalTypeIdWithCreatorTest extends BaseMapTest
{
// [databind#999]

public static interface Payload999 { }

@JsonTypeName("foo")
public static class FooPayload999 implements Payload999 { }

@JsonTypeName("bar")
public static class BarPayload999 implements Payload999 { }

public static class Message<P extends Payload999>
{
final String type;

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,
visible = true,
include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(FooPayload999.class),
@JsonSubTypes.Type(BarPayload999.class) })
final P payload;

@JsonCreator
public Message(@JsonProperty("type") String type,
@JsonProperty("payload") P payload)
{
this.type = type;
this.payload = payload;
}
}

// [databind#1198]

public enum Attacks { KICK, PUNCH }
Expand Down Expand Up @@ -46,44 +77,30 @@ public Punch(String side) {
}
}

// [databind#999]

public static interface Payload999 { }

@JsonTypeName("foo")
public static class FooPayload999 implements Payload999 { }
/*
/**********************************************************************
/* Test methods
/**********************************************************************
*/

@JsonTypeName("bar")
public static class BarPayload999 implements Payload999 { }
private final ObjectMapper MAPPER = newJsonMapper();

public static class Message<P extends Payload999>
// [databind#999]
public void testExternalTypeId() throws Exception
{
final String type;
TypeReference<Message<FooPayload999>> type = new TypeReference<Message<FooPayload999>>() { };

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,
visible = true,
include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(FooPayload999.class),
@JsonSubTypes.Type(BarPayload999.class) })
final P payload;
Message<?> msg = MAPPER.readValue(aposToQuotes("{ 'type':'foo', 'payload': {} }"), type);
assertNotNull(msg);
assertNotNull(msg.payload);
assertEquals("foo", msg.type);

@JsonCreator
public Message(@JsonProperty("type") String type,
@JsonProperty("payload") P payload)
{
this.type = type;
this.payload = payload;
}
// and then with different order
msg = MAPPER.readValue(aposToQuotes("{'payload': {}, 'type':'foo' }"), type);
assertNotNull(msg);
assertNotNull(msg.payload);
assertEquals("foo", msg.type);
}

/*
/**********************************************************************
/* Test methods
/**********************************************************************
*/

private final ObjectMapper MAPPER = new ObjectMapper();

// [databind#1198]
public void testFails() throws Exception {
Expand All @@ -106,21 +123,4 @@ public void testWorks() throws Exception {
assertNotNull(character.attack);
assertEquals("foo", character.name);
}

// [databind#999]
public void testExternalTypeId() throws Exception
{
TypeReference<Message<FooPayload999>> type = new TypeReference<Message<FooPayload999>>() { };

Message<?> msg = MAPPER.readValue(aposToQuotes("{ 'type':'foo', 'payload': {} }"), type);
assertNotNull(msg);
assertNotNull(msg.payload);
assertEquals("foo", msg.type);

// and then with different order
msg = MAPPER.readValue(aposToQuotes("{'payload': {}, 'type':'foo' }"), type);
assertNotNull(msg);
assertNotNull(msg.payload);
assertEquals("foo", msg.type);
}
}

0 comments on commit 6b20100

Please sign in to comment.