-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
(as reported by Joe O on mailing list)
Looks like one of following test methods fails:
public class JsonTypeInfoTest extends BaseMapTest
{
public enum Attacks { KICK, PUNCH }
static class Character {
public String name;
public Attacks preferredAttack;
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, defaultImpl=Kick.class,
include=JsonTypeInfo.As.EXTERNAL_PROPERTY, property="preferredAttack")
@JsonSubTypes({
@JsonSubTypes.Type(value=Kick.class, name="KICK"),
@JsonSubTypes.Type(value=Punch.class, name="PUNCH")
})
public Attack attack;
}
public static abstract class Attack {
public String side;
@JsonCreator
public Attack(String side) {
this.side = side;
}
}
public static class Kick extends Attack {
@JsonCreator
public Kick(String side) {
super(side);
}
}
public static class Punch extends Attack {
@JsonCreator
public Punch(String side) {
super(side);
}
}
final ObjectMapper MAPPER = new ObjectMapper();
public void testFails() throws Exception {
String json = "{ \"name\": \"foo\", \"attack\":\"right\" } }";
Character character = MAPPER.readValue(json, Character.class);
assertNotNull(character);
assertNotNull(character.attack);
assertEquals("foo", character.name);
}
public void testWorks() throws Exception {
String json = "{ \"name\": \"foo\", \"preferredAttack\": \"KICK\", \"attack\":\"right\" } }";
Character character = MAPPER.readValue(json, Character.class);
assertNotNull(character);
assertNotNull(character.attack);
assertEquals("foo", character.name);
}
}
with a NullPointerException
(with 2.7.3, current master
)
Metadata
Metadata
Assignees
Labels
No labels