Skip to content

Commit 9fce37f

Browse files
committed
Add support for a work-around needed for XML backend, "empty" polymorphic types.
1 parent d023767 commit 9fce37f

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ protected final Object _deserializeOther(JsonParser p, DeserializationContext ct
151151
case VALUE_TRUE:
152152
case VALUE_FALSE:
153153
return deserializeFromBoolean(p, ctxt);
154+
155+
case VALUE_NULL:
156+
return deserializeFromNull(p, ctxt);
154157
case START_ARRAY:
155158
// these only work if there's a (delegating) creator...
156159
return deserializeFromArray(p, ctxt);
@@ -164,8 +167,8 @@ protected final Object _deserializeOther(JsonParser p, DeserializationContext ct
164167
}
165168
return deserializeFromObject(p, ctxt);
166169
default:
167-
throw ctxt.mappingException(handledType());
168170
}
171+
throw ctxt.mappingException(handledType());
169172
}
170173

171174
protected Object _missingToken(JsonParser p, DeserializationContext ctxt) throws IOException {
@@ -467,6 +470,35 @@ protected final Object _deserializeWithErrorWrapping(JsonParser p,
467470
}
468471
}
469472

473+
/**
474+
* Helper method called for rare case of pointing to {@link JsonToken#VALUE_NULL}
475+
* token. While this is most often an erroneous condition, there is one specific
476+
* case with XML handling where polymorphic type with no properties is exposed
477+
* as such, and should be handled same as empty Object.
478+
*
479+
* @since 2.7
480+
*/
481+
protected Object deserializeFromNull(JsonParser p, DeserializationContext ctxt)
482+
throws IOException
483+
{
484+
// 17-Dec-2015, tatu: Highly specialized case, mainly to support polymorphic
485+
// "empty" POJOs deserialized from XML, where empty XML tag synthesizes a
486+
// `VALUE_NULL` token.
487+
if (p.requiresCustomCodec()) { // not only XML module, but mostly it...
488+
@SuppressWarnings("resource")
489+
TokenBuffer tb = new TokenBuffer(p, ctxt);
490+
tb.writeEndObject();
491+
JsonParser p2 = tb.asParser(p);
492+
p2.nextToken(); // to point to END_OBJECT
493+
// note: don't have ObjectId to consider at this point, so:
494+
Object ob = _vanillaProcessing ? vanillaDeserialize(p2, ctxt, JsonToken.END_OBJECT)
495+
: deserializeFromObject(p2, ctxt);
496+
p2.close();
497+
return ob;
498+
}
499+
throw ctxt.mappingException(handledType());
500+
}
501+
470502
/*
471503
/**********************************************************
472504
/* Deserializing when we have to consider an active View

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ public Object deserializeFromEmbedded(JsonParser p, DeserializationContext ctxt)
12691269

12701270
return p.getEmbeddedObject();
12711271
}
1272-
1272+
12731273
/*
12741274
/**********************************************************
12751275
/* Overridable helper methods

0 commit comments

Comments
 (0)