@@ -134,14 +134,14 @@ public BaseNodeDeserializer(Class<T> vc) {
134134 }
135135
136136 @ Override
137- public Object deserializeWithType (JsonParser jp , DeserializationContext ctxt ,
137+ public Object deserializeWithType (JsonParser p , DeserializationContext ctxt ,
138138 TypeDeserializer typeDeserializer )
139139 throws IOException
140140 {
141141 /* Output can be as JSON Object, Array or scalar: no way to know
142142 * a priori. So:
143143 */
144- return typeDeserializer .deserializeTypedFromAny (jp , ctxt );
144+ return typeDeserializer .deserializeTypedFromAny (p , ctxt );
145145 }
146146
147147 /* 07-Nov-2014, tatu: When investigating [databind#604], realized that it makes
@@ -157,8 +157,8 @@ public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
157157 /**********************************************************
158158 */
159159
160- protected void _reportProblem (JsonParser jp , String msg ) throws JsonMappingException {
161- throw new JsonMappingException (msg , jp .getTokenLocation ());
160+ protected void _reportProblem (JsonParser p , String msg ) throws JsonMappingException {
161+ throw new JsonMappingException (msg , p .getTokenLocation ());
162162 }
163163
164164 /**
@@ -187,15 +187,15 @@ protected void _handleDuplicateField(String fieldName, ObjectNode objectNode,
187187 * was added
188188 * @param newValue Newly added value just added to the object node
189189 */
190- protected void _handleDuplicateField (JsonParser jp , DeserializationContext ctxt ,
190+ protected void _handleDuplicateField (JsonParser p , DeserializationContext ctxt ,
191191 JsonNodeFactory nodeFactory ,
192192 String fieldName , ObjectNode objectNode ,
193193 JsonNode oldValue , JsonNode newValue )
194194 throws JsonProcessingException
195195 {
196196 // [Issue#237]: Report an error if asked to do so:
197197 if (ctxt .isEnabled (DeserializationFeature .FAIL_ON_READING_DUP_TREE_KEY )) {
198- _reportProblem (jp , "Duplicate field '" +fieldName +"' for ObjectNode: not allowed when FAIL_ON_READING_DUP_TREE_KEY enabled" );
198+ _reportProblem (p , "Duplicate field '" +fieldName +"' for ObjectNode: not allowed when FAIL_ON_READING_DUP_TREE_KEY enabled" );
199199 }
200200 // Backwards-compatibility; call in case it's overloaded
201201 _handleDuplicateField (fieldName , objectNode , oldValue , newValue );
@@ -207,30 +207,38 @@ protected void _handleDuplicateField(JsonParser jp, DeserializationContext ctxt,
207207 /**********************************************************
208208 */
209209
210- protected final ObjectNode deserializeObject (JsonParser jp , DeserializationContext ctxt ,
210+ protected final ObjectNode deserializeObject (JsonParser p , DeserializationContext ctxt ,
211211 final JsonNodeFactory nodeFactory ) throws IOException
212212 {
213213 ObjectNode node = nodeFactory .objectNode ();
214- JsonToken t = jp .getCurrentToken ();
215- if (t == JsonToken .START_OBJECT ) {
216- t = jp .nextToken ();
214+ String key ;
215+ if (p .isExpectedStartObjectToken ()) {
216+ key = p .nextFieldName ();
217+ } else {
218+ JsonToken t = p .getCurrentToken ();
219+ if (t == JsonToken .END_OBJECT ) {
220+ return node ;
221+ }
222+ if (t != JsonToken .FIELD_NAME ) {
223+ throw ctxt .mappingException (handledType (), p .getCurrentToken ());
224+ }
225+ key = p .getCurrentName ();
217226 }
218- for (; t == JsonToken .FIELD_NAME ; t = jp .nextToken ()) {
219- String fieldName = jp .getCurrentName ();
227+ for (; key != null ; key = p .nextFieldName ()) {
220228 JsonNode value ;
221- t = jp .nextToken ();
229+ JsonToken t = p .nextToken ();
222230 switch (t .id ()) {
223231 case JsonTokenId .ID_START_OBJECT :
224- value = deserializeObject (jp , ctxt , nodeFactory );
232+ value = deserializeObject (p , ctxt , nodeFactory );
225233 break ;
226234 case JsonTokenId .ID_START_ARRAY :
227- value = deserializeArray (jp , ctxt , nodeFactory );
235+ value = deserializeArray (p , ctxt , nodeFactory );
228236 break ;
229237 case JsonTokenId .ID_STRING :
230- value = nodeFactory .textNode (jp .getText ());
238+ value = nodeFactory .textNode (p .getText ());
231239 break ;
232240 case JsonTokenId .ID_NUMBER_INT :
233- value = _fromInt (jp , ctxt , nodeFactory );
241+ value = _fromInt (p , ctxt , nodeFactory );
234242 break ;
235243 case JsonTokenId .ID_TRUE :
236244 value = nodeFactory .booleanNode (true );
@@ -242,40 +250,40 @@ protected final ObjectNode deserializeObject(JsonParser jp, DeserializationConte
242250 value = nodeFactory .nullNode ();
243251 break ;
244252 default :
245- value = deserializeAny (jp , ctxt , nodeFactory );
253+ value = deserializeAny (p , ctxt , nodeFactory );
246254 }
247- JsonNode old = node .replace (fieldName , value );
255+ JsonNode old = node .replace (key , value );
248256 if (old != null ) {
249- _handleDuplicateField (jp , ctxt , nodeFactory ,
250- fieldName , node , old , value );
257+ _handleDuplicateField (p , ctxt , nodeFactory ,
258+ key , node , old , value );
251259 }
252260 }
253261 return node ;
254262 }
255263
256- protected final ArrayNode deserializeArray (JsonParser jp , DeserializationContext ctxt ,
264+ protected final ArrayNode deserializeArray (JsonParser p , DeserializationContext ctxt ,
257265 final JsonNodeFactory nodeFactory ) throws IOException
258266 {
259267 ArrayNode node = nodeFactory .arrayNode ();
260268 while (true ) {
261- JsonToken t = jp .nextToken ();
269+ JsonToken t = p .nextToken ();
262270 if (t == null ) {
263271 throw ctxt .mappingException ("Unexpected end-of-input when binding data into ArrayNode" );
264272 }
265273 switch (t .id ()) {
266274 case JsonTokenId .ID_START_OBJECT :
267- node .add (deserializeObject (jp , ctxt , nodeFactory ));
275+ node .add (deserializeObject (p , ctxt , nodeFactory ));
268276 break ;
269277 case JsonTokenId .ID_START_ARRAY :
270- node .add (deserializeArray (jp , ctxt , nodeFactory ));
278+ node .add (deserializeArray (p , ctxt , nodeFactory ));
271279 break ;
272280 case JsonTokenId .ID_END_ARRAY :
273281 return node ;
274282 case JsonTokenId .ID_STRING :
275- node .add (nodeFactory .textNode (jp .getText ()));
283+ node .add (nodeFactory .textNode (p .getText ()));
276284 break ;
277285 case JsonTokenId .ID_NUMBER_INT :
278- node .add (_fromInt (jp , ctxt , nodeFactory ));
286+ node .add (_fromInt (p , ctxt , nodeFactory ));
279287 break ;
280288 case JsonTokenId .ID_TRUE :
281289 node .add (nodeFactory .booleanNode (true ));
@@ -287,31 +295,31 @@ protected final ArrayNode deserializeArray(JsonParser jp, DeserializationContext
287295 node .add (nodeFactory .nullNode ());
288296 break ;
289297 default :
290- node .add (deserializeAny (jp , ctxt , nodeFactory ));
298+ node .add (deserializeAny (p , ctxt , nodeFactory ));
291299 break ;
292300 }
293301 }
294302 }
295303
296- protected final JsonNode deserializeAny (JsonParser jp , DeserializationContext ctxt ,
304+ protected final JsonNode deserializeAny (JsonParser p , DeserializationContext ctxt ,
297305 final JsonNodeFactory nodeFactory ) throws IOException
298306 {
299- switch (jp .getCurrentTokenId ()) {
307+ switch (p .getCurrentTokenId ()) {
300308 case JsonTokenId .ID_START_OBJECT :
301309 case JsonTokenId .ID_END_OBJECT : // for empty JSON Objects we may point to this
302- return deserializeObject (jp , ctxt , nodeFactory );
310+ return deserializeObject (p , ctxt , nodeFactory );
303311 case JsonTokenId .ID_START_ARRAY :
304- return deserializeArray (jp , ctxt , nodeFactory );
312+ return deserializeArray (p , ctxt , nodeFactory );
305313 case JsonTokenId .ID_FIELD_NAME :
306- return deserializeObject (jp , ctxt , nodeFactory );
314+ return deserializeObject (p , ctxt , nodeFactory );
307315 case JsonTokenId .ID_EMBEDDED_OBJECT :
308- return _fromEmbedded (jp , ctxt , nodeFactory );
316+ return _fromEmbedded (p , ctxt , nodeFactory );
309317 case JsonTokenId .ID_STRING :
310- return nodeFactory .textNode (jp .getText ());
318+ return nodeFactory .textNode (p .getText ());
311319 case JsonTokenId .ID_NUMBER_INT :
312- return _fromInt (jp , ctxt , nodeFactory );
320+ return _fromInt (p , ctxt , nodeFactory );
313321 case JsonTokenId .ID_NUMBER_FLOAT :
314- return _fromFloat (jp , ctxt , nodeFactory );
322+ return _fromFloat (p , ctxt , nodeFactory );
315323 case JsonTokenId .ID_TRUE :
316324 return nodeFactory .booleanNode (true );
317325 case JsonTokenId .ID_FALSE :
@@ -329,36 +337,36 @@ protected final JsonNode deserializeAny(JsonParser jp, DeserializationContext ct
329337 }
330338 }
331339
332- protected final JsonNode _fromInt (JsonParser jp , DeserializationContext ctxt ,
340+ protected final JsonNode _fromInt (JsonParser p , DeserializationContext ctxt ,
333341 JsonNodeFactory nodeFactory ) throws IOException
334342 {
335- JsonParser .NumberType nt = jp .getNumberType ();
343+ JsonParser .NumberType nt = p .getNumberType ();
336344 if (nt == JsonParser .NumberType .BIG_INTEGER
337345 || ctxt .isEnabled (DeserializationFeature .USE_BIG_INTEGER_FOR_INTS )) {
338- return nodeFactory .numberNode (jp .getBigIntegerValue ());
346+ return nodeFactory .numberNode (p .getBigIntegerValue ());
339347 }
340348 if (nt == JsonParser .NumberType .INT ) {
341- return nodeFactory .numberNode (jp .getIntValue ());
349+ return nodeFactory .numberNode (p .getIntValue ());
342350 }
343- return nodeFactory .numberNode (jp .getLongValue ());
351+ return nodeFactory .numberNode (p .getLongValue ());
344352 }
345353
346- protected final JsonNode _fromFloat (JsonParser jp , DeserializationContext ctxt ,
354+ protected final JsonNode _fromFloat (JsonParser p , DeserializationContext ctxt ,
347355 final JsonNodeFactory nodeFactory ) throws IOException
348356 {
349- JsonParser .NumberType nt = jp .getNumberType ();
357+ JsonParser .NumberType nt = p .getNumberType ();
350358 if (nt == JsonParser .NumberType .BIG_DECIMAL
351359 || ctxt .isEnabled (DeserializationFeature .USE_BIG_DECIMAL_FOR_FLOATS )) {
352- return nodeFactory .numberNode (jp .getDecimalValue ());
360+ return nodeFactory .numberNode (p .getDecimalValue ());
353361 }
354- return nodeFactory .numberNode (jp .getDoubleValue ());
362+ return nodeFactory .numberNode (p .getDoubleValue ());
355363 }
356364
357- protected final JsonNode _fromEmbedded (JsonParser jp , DeserializationContext ctxt ,
365+ protected final JsonNode _fromEmbedded (JsonParser p , DeserializationContext ctxt ,
358366 JsonNodeFactory nodeFactory ) throws IOException
359367 {
360368 // [JACKSON-796]
361- Object ob = jp .getEmbeddedObject ();
369+ Object ob = p .getEmbeddedObject ();
362370 if (ob == null ) { // should this occur?
363371 return nodeFactory .nullNode ();
364372 }
0 commit comments