@@ -76,45 +76,46 @@ public Object deserializeTypedFromAny(JsonParser jp, DeserializationContext ctxt
76
76
* deserialization.
77
77
*/
78
78
@ SuppressWarnings ("resource" )
79
- protected Object _deserialize (JsonParser jp , DeserializationContext ctxt ) throws IOException
79
+ protected Object _deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException
80
80
{
81
81
// 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 ();
84
84
if (typeId != null ) {
85
- return _deserializeWithNativeTypeId (jp , ctxt , typeId );
85
+ return _deserializeWithNativeTypeId (p , ctxt , typeId );
86
86
}
87
87
}
88
-
89
88
// 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 ,
92
98
"need JSON Object to contain As.WRAPPER_OBJECT type information for class " +baseTypeName ());
93
99
}
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 ();
100
101
JsonDeserializer <Object > deser = _findDeserializer (ctxt , typeId );
101
- jp .nextToken ();
102
+ p .nextToken ();
102
103
103
104
// 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 ) {
105
106
// but what if there's nowhere to add it in? Error? Or skip? For now, skip.
106
107
TokenBuffer tb = new TokenBuffer (null , false );
107
108
tb .writeStartObject (); // recreate START_OBJECT
108
109
tb .writeFieldName (_typePropertyName );
109
110
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 ();
112
113
}
113
114
114
- Object value = deser .deserialize (jp , ctxt );
115
+ Object value = deser .deserialize (p , ctxt );
115
116
// 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 ,
118
119
"expected closing END_OBJECT after type information and deserialized value" );
119
120
}
120
121
return value ;
0 commit comments