Skip to content

Commit 308ed4e

Browse files
committed
Fix #1108
1 parent e741034 commit 308ed4e

File tree

4 files changed

+61
-14
lines changed

4 files changed

+61
-14
lines changed

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Project: jackson-databind
88

99
#1088: NPE possibility in SimpleMixinResolver
1010
(reported by Laird N)
11+
#1108: Jackson not continue to parse after DeserializationFeature.FAIL_ON_INVALID_SUBTYPE error
12+
(reported by jefferyyuan@github)
1113

1214
2.6.5 (19-Jan-2016)
1315

src/main/java/com/fasterxml/jackson/databind/deser/std/NullifyingDeserializer.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,35 @@ public class NullifyingDeserializer
2828
*/
2929

3030
@Override
31-
public Object deserialize(JsonParser jp, DeserializationContext ctxt)
32-
throws IOException, JsonProcessingException
31+
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
3332
{
34-
jp.skipChildren();
33+
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
34+
// special unfortunately
35+
if (p.hasToken(JsonToken.FIELD_NAME)) {
36+
while (true) {
37+
JsonToken t = p.nextToken();
38+
if ((t == null) || (t == JsonToken.END_OBJECT)) {
39+
break;
40+
}
41+
p.skipChildren();
42+
}
43+
} else {
44+
p.skipChildren();
45+
}
3546
return null;
3647
}
3748

3849
@Override
39-
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
40-
TypeDeserializer typeDeserializer)
41-
throws IOException, JsonProcessingException
50+
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
51+
TypeDeserializer typeDeserializer) throws IOException
4252
{
4353
// Not sure if we need to bother but:
4454

45-
JsonToken t = jp.getCurrentToken();
46-
switch (t) {
47-
case START_ARRAY:
48-
case START_OBJECT:
49-
case FIELD_NAME:
50-
return typeDeserializer.deserializeTypedFromAny(jp, ctxt);
55+
switch (p.getCurrentTokenId()) {
56+
case JsonTokenId.ID_START_ARRAY:
57+
case JsonTokenId.ID_START_OBJECT:
58+
case JsonTokenId.ID_FIELD_NAME:
59+
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
5160
default:
5261
return null;
5362
}

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeDeserializerBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected final JsonDeserializer<Object> _findDeserializer(DeserializationContex
185185

186186
protected final JsonDeserializer<Object> _findDefaultImplDeserializer(DeserializationContext ctxt) throws IOException
187187
{
188-
/* 06-Feb-2013, tatu: As per [Issue#148], consider default implementation value of
188+
/* 06-Feb-2013, tatu: As per [databind#148], consider default implementation value of
189189
* {@link java.lang.Void} to mean "serialize as null"; as well as DeserializationFeature
190190
* to do swift mapping to null
191191
*/

src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicWithDefaultImpl.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ static class ImplFor656 extends BaseFor656 {
105105
public int a;
106106
}
107107

108+
static class CallRecord {
109+
public float version;
110+
public String application;
111+
public Item item;
112+
public Item item2;
113+
public CallRecord() {}
114+
}
115+
116+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
117+
@JsonSubTypes({@JsonSubTypes.Type(value = Event.class, name = "event")})
118+
@JsonIgnoreProperties(ignoreUnknown=true)
119+
public interface Item { }
120+
121+
static class Event implements Item {
122+
public String location;
123+
public Event() {}
124+
}
125+
108126
/*
109127
/**********************************************************
110128
/* Unit tests, deserialization
@@ -193,7 +211,25 @@ public void testDefaultImplWithObjectWrapper() throws Exception
193211
assertEquals(ImplFor656.class, value.getClass());
194212
assertEquals(3, ((ImplFor656) value).a);
195213
}
196-
214+
215+
public void testUnknownTypeIDRecovery() throws Exception
216+
{
217+
ObjectReader reader = MAPPER.readerFor(CallRecord.class).without(
218+
DeserializationFeature.FAIL_ON_INVALID_SUBTYPE);
219+
String json = aposToQuotes("{'version':0.0,'application':'123',"
220+
+"'item':{'type':'xevent','location':'location1'},"
221+
+"'item2':{'type':'event','location':'location1'}}");
222+
// can't read item2 - which is valid
223+
CallRecord r = reader.readValue(json);
224+
assertNull(r.item);
225+
assertNotNull(r.item2);
226+
227+
json = aposToQuotes("{'item':{'type':'xevent','location':'location1'}, 'version':0.0,'application':'123'}");
228+
CallRecord r3 = reader.readValue(json);
229+
assertNull(r3.item);
230+
assertEquals("123", r3.application);
231+
}
232+
197233
/*
198234
/**********************************************************
199235
/* Unit tests, serialization

0 commit comments

Comments
 (0)