@@ -134,14 +134,14 @@ public BaseNodeDeserializer(Class<T> vc) {
134
134
}
135
135
136
136
@ Override
137
- public Object deserializeWithType (JsonParser jp , DeserializationContext ctxt ,
137
+ public Object deserializeWithType (JsonParser p , DeserializationContext ctxt ,
138
138
TypeDeserializer typeDeserializer )
139
139
throws IOException
140
140
{
141
141
/* Output can be as JSON Object, Array or scalar: no way to know
142
142
* a priori. So:
143
143
*/
144
- return typeDeserializer .deserializeTypedFromAny (jp , ctxt );
144
+ return typeDeserializer .deserializeTypedFromAny (p , ctxt );
145
145
}
146
146
147
147
/* 07-Nov-2014, tatu: When investigating [databind#604], realized that it makes
@@ -157,8 +157,8 @@ public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
157
157
/**********************************************************
158
158
*/
159
159
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 ());
162
162
}
163
163
164
164
/**
@@ -187,15 +187,15 @@ protected void _handleDuplicateField(String fieldName, ObjectNode objectNode,
187
187
* was added
188
188
* @param newValue Newly added value just added to the object node
189
189
*/
190
- protected void _handleDuplicateField (JsonParser jp , DeserializationContext ctxt ,
190
+ protected void _handleDuplicateField (JsonParser p , DeserializationContext ctxt ,
191
191
JsonNodeFactory nodeFactory ,
192
192
String fieldName , ObjectNode objectNode ,
193
193
JsonNode oldValue , JsonNode newValue )
194
194
throws JsonProcessingException
195
195
{
196
196
// [Issue#237]: Report an error if asked to do so:
197
197
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" );
199
199
}
200
200
// Backwards-compatibility; call in case it's overloaded
201
201
_handleDuplicateField (fieldName , objectNode , oldValue , newValue );
@@ -207,30 +207,38 @@ protected void _handleDuplicateField(JsonParser jp, DeserializationContext ctxt,
207
207
/**********************************************************
208
208
*/
209
209
210
- protected final ObjectNode deserializeObject (JsonParser jp , DeserializationContext ctxt ,
210
+ protected final ObjectNode deserializeObject (JsonParser p , DeserializationContext ctxt ,
211
211
final JsonNodeFactory nodeFactory ) throws IOException
212
212
{
213
213
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 ();
217
226
}
218
- for (; t == JsonToken .FIELD_NAME ; t = jp .nextToken ()) {
219
- String fieldName = jp .getCurrentName ();
227
+ for (; key != null ; key = p .nextFieldName ()) {
220
228
JsonNode value ;
221
- t = jp .nextToken ();
229
+ JsonToken t = p .nextToken ();
222
230
switch (t .id ()) {
223
231
case JsonTokenId .ID_START_OBJECT :
224
- value = deserializeObject (jp , ctxt , nodeFactory );
232
+ value = deserializeObject (p , ctxt , nodeFactory );
225
233
break ;
226
234
case JsonTokenId .ID_START_ARRAY :
227
- value = deserializeArray (jp , ctxt , nodeFactory );
235
+ value = deserializeArray (p , ctxt , nodeFactory );
228
236
break ;
229
237
case JsonTokenId .ID_STRING :
230
- value = nodeFactory .textNode (jp .getText ());
238
+ value = nodeFactory .textNode (p .getText ());
231
239
break ;
232
240
case JsonTokenId .ID_NUMBER_INT :
233
- value = _fromInt (jp , ctxt , nodeFactory );
241
+ value = _fromInt (p , ctxt , nodeFactory );
234
242
break ;
235
243
case JsonTokenId .ID_TRUE :
236
244
value = nodeFactory .booleanNode (true );
@@ -242,40 +250,40 @@ protected final ObjectNode deserializeObject(JsonParser jp, DeserializationConte
242
250
value = nodeFactory .nullNode ();
243
251
break ;
244
252
default :
245
- value = deserializeAny (jp , ctxt , nodeFactory );
253
+ value = deserializeAny (p , ctxt , nodeFactory );
246
254
}
247
- JsonNode old = node .replace (fieldName , value );
255
+ JsonNode old = node .replace (key , value );
248
256
if (old != null ) {
249
- _handleDuplicateField (jp , ctxt , nodeFactory ,
250
- fieldName , node , old , value );
257
+ _handleDuplicateField (p , ctxt , nodeFactory ,
258
+ key , node , old , value );
251
259
}
252
260
}
253
261
return node ;
254
262
}
255
263
256
- protected final ArrayNode deserializeArray (JsonParser jp , DeserializationContext ctxt ,
264
+ protected final ArrayNode deserializeArray (JsonParser p , DeserializationContext ctxt ,
257
265
final JsonNodeFactory nodeFactory ) throws IOException
258
266
{
259
267
ArrayNode node = nodeFactory .arrayNode ();
260
268
while (true ) {
261
- JsonToken t = jp .nextToken ();
269
+ JsonToken t = p .nextToken ();
262
270
if (t == null ) {
263
271
throw ctxt .mappingException ("Unexpected end-of-input when binding data into ArrayNode" );
264
272
}
265
273
switch (t .id ()) {
266
274
case JsonTokenId .ID_START_OBJECT :
267
- node .add (deserializeObject (jp , ctxt , nodeFactory ));
275
+ node .add (deserializeObject (p , ctxt , nodeFactory ));
268
276
break ;
269
277
case JsonTokenId .ID_START_ARRAY :
270
- node .add (deserializeArray (jp , ctxt , nodeFactory ));
278
+ node .add (deserializeArray (p , ctxt , nodeFactory ));
271
279
break ;
272
280
case JsonTokenId .ID_END_ARRAY :
273
281
return node ;
274
282
case JsonTokenId .ID_STRING :
275
- node .add (nodeFactory .textNode (jp .getText ()));
283
+ node .add (nodeFactory .textNode (p .getText ()));
276
284
break ;
277
285
case JsonTokenId .ID_NUMBER_INT :
278
- node .add (_fromInt (jp , ctxt , nodeFactory ));
286
+ node .add (_fromInt (p , ctxt , nodeFactory ));
279
287
break ;
280
288
case JsonTokenId .ID_TRUE :
281
289
node .add (nodeFactory .booleanNode (true ));
@@ -287,31 +295,31 @@ protected final ArrayNode deserializeArray(JsonParser jp, DeserializationContext
287
295
node .add (nodeFactory .nullNode ());
288
296
break ;
289
297
default :
290
- node .add (deserializeAny (jp , ctxt , nodeFactory ));
298
+ node .add (deserializeAny (p , ctxt , nodeFactory ));
291
299
break ;
292
300
}
293
301
}
294
302
}
295
303
296
- protected final JsonNode deserializeAny (JsonParser jp , DeserializationContext ctxt ,
304
+ protected final JsonNode deserializeAny (JsonParser p , DeserializationContext ctxt ,
297
305
final JsonNodeFactory nodeFactory ) throws IOException
298
306
{
299
- switch (jp .getCurrentTokenId ()) {
307
+ switch (p .getCurrentTokenId ()) {
300
308
case JsonTokenId .ID_START_OBJECT :
301
309
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 );
303
311
case JsonTokenId .ID_START_ARRAY :
304
- return deserializeArray (jp , ctxt , nodeFactory );
312
+ return deserializeArray (p , ctxt , nodeFactory );
305
313
case JsonTokenId .ID_FIELD_NAME :
306
- return deserializeObject (jp , ctxt , nodeFactory );
314
+ return deserializeObject (p , ctxt , nodeFactory );
307
315
case JsonTokenId .ID_EMBEDDED_OBJECT :
308
- return _fromEmbedded (jp , ctxt , nodeFactory );
316
+ return _fromEmbedded (p , ctxt , nodeFactory );
309
317
case JsonTokenId .ID_STRING :
310
- return nodeFactory .textNode (jp .getText ());
318
+ return nodeFactory .textNode (p .getText ());
311
319
case JsonTokenId .ID_NUMBER_INT :
312
- return _fromInt (jp , ctxt , nodeFactory );
320
+ return _fromInt (p , ctxt , nodeFactory );
313
321
case JsonTokenId .ID_NUMBER_FLOAT :
314
- return _fromFloat (jp , ctxt , nodeFactory );
322
+ return _fromFloat (p , ctxt , nodeFactory );
315
323
case JsonTokenId .ID_TRUE :
316
324
return nodeFactory .booleanNode (true );
317
325
case JsonTokenId .ID_FALSE :
@@ -329,36 +337,36 @@ protected final JsonNode deserializeAny(JsonParser jp, DeserializationContext ct
329
337
}
330
338
}
331
339
332
- protected final JsonNode _fromInt (JsonParser jp , DeserializationContext ctxt ,
340
+ protected final JsonNode _fromInt (JsonParser p , DeserializationContext ctxt ,
333
341
JsonNodeFactory nodeFactory ) throws IOException
334
342
{
335
- JsonParser .NumberType nt = jp .getNumberType ();
343
+ JsonParser .NumberType nt = p .getNumberType ();
336
344
if (nt == JsonParser .NumberType .BIG_INTEGER
337
345
|| ctxt .isEnabled (DeserializationFeature .USE_BIG_INTEGER_FOR_INTS )) {
338
- return nodeFactory .numberNode (jp .getBigIntegerValue ());
346
+ return nodeFactory .numberNode (p .getBigIntegerValue ());
339
347
}
340
348
if (nt == JsonParser .NumberType .INT ) {
341
- return nodeFactory .numberNode (jp .getIntValue ());
349
+ return nodeFactory .numberNode (p .getIntValue ());
342
350
}
343
- return nodeFactory .numberNode (jp .getLongValue ());
351
+ return nodeFactory .numberNode (p .getLongValue ());
344
352
}
345
353
346
- protected final JsonNode _fromFloat (JsonParser jp , DeserializationContext ctxt ,
354
+ protected final JsonNode _fromFloat (JsonParser p , DeserializationContext ctxt ,
347
355
final JsonNodeFactory nodeFactory ) throws IOException
348
356
{
349
- JsonParser .NumberType nt = jp .getNumberType ();
357
+ JsonParser .NumberType nt = p .getNumberType ();
350
358
if (nt == JsonParser .NumberType .BIG_DECIMAL
351
359
|| ctxt .isEnabled (DeserializationFeature .USE_BIG_DECIMAL_FOR_FLOATS )) {
352
- return nodeFactory .numberNode (jp .getDecimalValue ());
360
+ return nodeFactory .numberNode (p .getDecimalValue ());
353
361
}
354
- return nodeFactory .numberNode (jp .getDoubleValue ());
362
+ return nodeFactory .numberNode (p .getDoubleValue ());
355
363
}
356
364
357
- protected final JsonNode _fromEmbedded (JsonParser jp , DeserializationContext ctxt ,
365
+ protected final JsonNode _fromEmbedded (JsonParser p , DeserializationContext ctxt ,
358
366
JsonNodeFactory nodeFactory ) throws IOException
359
367
{
360
368
// [JACKSON-796]
361
- Object ob = jp .getEmbeddedObject ();
369
+ Object ob = p .getEmbeddedObject ();
362
370
if (ob == null ) { // should this occur?
363
371
return nodeFactory .nullNode ();
364
372
}
0 commit comments