@@ -76,45 +76,46 @@ public Object deserializeTypedFromAny(JsonParser jp, DeserializationContext ctxt
7676 * deserialization.
7777 */
7878 @ SuppressWarnings ("resource" )
79- protected Object _deserialize (JsonParser jp , DeserializationContext ctxt ) throws IOException
79+ protected Object _deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException
8080 {
8181 // 02-Aug-2013, tatu: May need to use native type ids
82- if (jp .canReadTypeId ()) {
83- Object typeId = jp .getTypeId ();
82+ if (p .canReadTypeId ()) {
83+ Object typeId = p .getTypeId ();
8484 if (typeId != null ) {
85- return _deserializeWithNativeTypeId (jp , ctxt , typeId );
85+ return _deserializeWithNativeTypeId (p , ctxt , typeId );
8686 }
8787 }
88-
8988 // first, sanity checks
90- if (jp .getCurrentToken () != JsonToken .START_OBJECT ) {
91- throw ctxt .wrongTokenException (jp , JsonToken .START_OBJECT ,
89+ JsonToken t = p .getCurrentToken ();
90+ if (t == JsonToken .START_OBJECT ) {
91+ // should always get field name, but just in case...
92+ if (p .nextToken () != JsonToken .FIELD_NAME ) {
93+ throw ctxt .wrongTokenException (p , JsonToken .FIELD_NAME ,
94+ "need JSON String that contains type id (for subtype of " +baseTypeName ()+")" );
95+ }
96+ } else if (t != JsonToken .FIELD_NAME ) {
97+ throw ctxt .wrongTokenException (p , JsonToken .START_OBJECT ,
9298 "need JSON Object to contain As.WRAPPER_OBJECT type information for class " +baseTypeName ());
9399 }
94- // should always get field name, but just in case...
95- if (jp .nextToken () != JsonToken .FIELD_NAME ) {
96- throw ctxt .wrongTokenException (jp , JsonToken .FIELD_NAME ,
97- "need JSON String that contains type id (for subtype of " +baseTypeName ()+")" );
98- }
99- final String typeId = jp .getText ();
100+ final String typeId = p .getText ();
100101 JsonDeserializer <Object > deser = _findDeserializer (ctxt , typeId );
101- jp .nextToken ();
102+ p .nextToken ();
102103
103104 // Minor complication: we may need to merge type id in?
104- if (_typeIdVisible && jp .getCurrentToken () == JsonToken .START_OBJECT ) {
105+ if (_typeIdVisible && p .getCurrentToken () == JsonToken .START_OBJECT ) {
105106 // but what if there's nowhere to add it in? Error? Or skip? For now, skip.
106107 TokenBuffer tb = new TokenBuffer (null , false );
107108 tb .writeStartObject (); // recreate START_OBJECT
108109 tb .writeFieldName (_typePropertyName );
109110 tb .writeString (typeId );
110- jp = JsonParserSequence .createFlattened (tb .asParser (jp ), jp );
111- jp .nextToken ();
111+ p = JsonParserSequence .createFlattened (tb .asParser (p ), p );
112+ p .nextToken ();
112113 }
113114
114- Object value = deser .deserialize (jp , ctxt );
115+ Object value = deser .deserialize (p , ctxt );
115116 // And then need the closing END_OBJECT
116- if (jp .nextToken () != JsonToken .END_OBJECT ) {
117- throw ctxt .wrongTokenException (jp , JsonToken .END_OBJECT ,
117+ if (p .nextToken () != JsonToken .END_OBJECT ) {
118+ throw ctxt .wrongTokenException (p , JsonToken .END_OBJECT ,
118119 "expected closing END_OBJECT after type information and deserialized value" );
119120 }
120121 return value ;
0 commit comments