@@ -20,20 +20,13 @@ public class BeanDeserializer
20
20
{
21
21
/* TODOs for future versions:
22
22
*
23
- * For 2.6
24
- *
25
- * - Start using new (2.5) methods in JsonParser, like
26
- * * 'hasTokenId(xxx)'
27
- * * 'nextFieldName()'
28
- *
29
- * for slightly more efficient property lookups, handling
30
- * (2-3% faster deserialization)
31
- * Not done for 2.5 since it was just introduced, trying to
32
- * keep some level of compatibility between "adjacent" minor
33
- * versions.
34
- * Also: need to ensure efficient impl of those methods for Smile, CBOR
35
- * at least (in addition to JSON)
23
+ * For 2.6?
36
24
*
25
+ * - New method in JsonDeserializer (deserializeNext()) to allow use of more
26
+ * efficient 'nextXxx()' method `JsonParser` provides.
27
+ *
28
+ * Also: need to ensure efficient impl of those methods for Smile, CBOR
29
+ * at least (in addition to JSON)
37
30
*/
38
31
39
32
private static final long serialVersionUID = 1L ;
@@ -47,8 +40,7 @@ public class BeanDeserializer
47
40
/**
48
41
* Constructor used by {@link BeanDeserializerBuilder}.
49
42
*/
50
- public BeanDeserializer (BeanDeserializerBuilder builder ,
51
- BeanDescription beanDesc ,
43
+ public BeanDeserializer (BeanDeserializerBuilder builder , BeanDescription beanDesc ,
52
44
BeanPropertyMap properties , Map <String , SettableBeanProperty > backRefs ,
53
45
HashSet <String > ignorableProps , boolean ignoreAllUnknown ,
54
46
boolean hasViews )
@@ -126,12 +118,10 @@ protected BeanDeserializerBase asArrayDeserializer() {
126
118
* like Afterburner change definition.
127
119
*/
128
120
@ Override
129
- public Object deserialize (JsonParser p , DeserializationContext ctxt )
130
- throws IOException
121
+ public Object deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException
131
122
{
132
- JsonToken t = p .getCurrentToken ();
133
123
// common case first
134
- if (t == JsonToken . START_OBJECT ) { // TODO: in 2.6, use 'p.hasTokenId()'
124
+ if (p . isExpectedStartObjectToken ()) {
135
125
if (_vanillaProcessing ) {
136
126
return vanillaDeserialize (p , ctxt , p .nextToken ());
137
127
}
@@ -141,6 +131,7 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt)
141
131
}
142
132
return deserializeFromObject (p , ctxt );
143
133
}
134
+ JsonToken t = p .getCurrentToken ();
144
135
return _deserializeOther (p , ctxt , t );
145
136
}
146
137
@@ -177,9 +168,7 @@ protected final Object _deserializeOther(JsonParser p, DeserializationContext ct
177
168
}
178
169
}
179
170
180
- protected Object _missingToken (JsonParser p , DeserializationContext ctxt )
181
- throws JsonProcessingException
182
- {
171
+ protected Object _missingToken (JsonParser p , DeserializationContext ctxt ) throws IOException {
183
172
throw ctxt .endOfInputException (handledType ());
184
173
}
185
174
@@ -189,8 +178,7 @@ protected Object _missingToken(JsonParser p, DeserializationContext ctxt)
189
178
* after collecting some or all of the properties to set.
190
179
*/
191
180
@ Override
192
- public Object deserialize (JsonParser p , DeserializationContext ctxt , Object bean )
193
- throws IOException
181
+ public Object deserialize (JsonParser p , DeserializationContext ctxt , Object bean ) throws IOException
194
182
{
195
183
// [databind#631]: Assign current value, to be accessible by custom serializers
196
184
p .setCurrentValue (bean );
@@ -203,24 +191,33 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt, Object bean
203
191
if (_externalTypeIdHandler != null ) {
204
192
return deserializeWithExternalTypeId (p , ctxt , bean );
205
193
}
206
- JsonToken t = p .getCurrentToken ();
194
+ String propName ;
195
+
207
196
// 23-Mar-2010, tatu: In some cases, we start with full JSON object too...
208
- if (t == JsonToken .START_OBJECT ) {
209
- t = p .nextToken ();
197
+ if (p .isExpectedStartObjectToken ()) {
198
+ propName = p .nextFieldName ();
199
+ if (propName == null ) {
200
+ return bean ;
201
+ }
202
+ } else {
203
+ if (p .hasTokenId (JsonTokenId .ID_FIELD_NAME )) {
204
+ propName = p .getCurrentName ();
205
+ } else {
206
+ return bean ;
207
+ }
210
208
}
211
209
if (_needViewProcesing ) {
212
210
Class <?> view = ctxt .getActiveView ();
213
211
if (view != null ) {
214
212
return deserializeWithView (p , ctxt , bean , view );
215
213
}
216
214
}
217
- for (; t == JsonToken .FIELD_NAME ; t = p .nextToken ()) {
218
- String propName = p .getCurrentName ();
215
+ do {
219
216
p .nextToken ();
220
217
if (!_beanProperties .findDeserializeAndSet (p , ctxt , bean , propName )) {
221
218
handleUnknownVanilla (p , ctxt , bean , propName );
222
219
}
223
- }
220
+ } while (( propName = p . nextFieldName ()) != null );
224
221
return bean ;
225
222
}
226
223
@@ -241,17 +238,6 @@ private final Object vanillaDeserialize(JsonParser p,
241
238
final Object bean = _valueInstantiator .createUsingDefault (ctxt );
242
239
// [databind#631]: Assign current value, to be accessible by custom serializers
243
240
p .setCurrentValue (bean );
244
-
245
- for (; t == JsonToken .FIELD_NAME ; t = p .nextToken ()) {
246
- String propName = p .getCurrentName ();
247
- p .nextToken ();
248
- if (!_beanProperties .findDeserializeAndSet (p , ctxt , bean , propName )) {
249
- handleUnknownVanilla (p , ctxt , bean , propName );
250
- }
251
- }
252
-
253
- // 13-Dec-2014, tatu: For 2.6, we'll do:
254
- /*
255
241
if (p .hasTokenId (JsonTokenId .ID_FIELD_NAME )) {
256
242
String propName = p .getCurrentName ();
257
243
do {
@@ -261,7 +247,6 @@ private final Object vanillaDeserialize(JsonParser p,
261
247
}
262
248
} while ((propName = p .nextFieldName ()) != null );
263
249
}
264
- */
265
250
return bean ;
266
251
}
267
252
@@ -280,7 +265,7 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t
280
265
*/
281
266
if (_objectIdReader != null && _objectIdReader .maySerializeAsObject ()) {
282
267
// TODO: in 2.6, use 'p.hasTokenId()'
283
- if (( p . getCurrentTokenId () == JsonTokenId .ID_FIELD_NAME )
268
+ if (p . hasTokenId ( JsonTokenId .ID_FIELD_NAME )
284
269
&& _objectIdReader .isValidReferencePropertyName (p .getCurrentName (), p )) {
285
270
return deserializeFromObjectId (p , ctxt );
286
271
}
@@ -328,16 +313,6 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t
328
313
return deserializeWithView (p , ctxt , bean , view );
329
314
}
330
315
}
331
- JsonToken t = p .getCurrentToken ();
332
- for (; t == JsonToken .FIELD_NAME ; t = p .nextToken ()) {
333
- String propName = p .getCurrentName ();
334
- p .nextToken ();
335
- if (!_beanProperties .findDeserializeAndSet (p , ctxt , bean , propName )) {
336
- handleUnknownVanilla (p , ctxt , bean , propName );
337
- }
338
- }
339
- // 13-Dec-2014, tatu: For 2.6, we'll do:
340
- /*
341
316
if (p .hasTokenId (JsonTokenId .ID_FIELD_NAME )) {
342
317
String propName = p .getCurrentName ();
343
318
do {
@@ -347,7 +322,6 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t
347
322
}
348
323
} while ((propName = p .nextFieldName ()) != null );
349
324
}
350
- */
351
325
return bean ;
352
326
}
353
327
@@ -459,30 +433,31 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
459
433
/* Deserializing when we have to consider an active View
460
434
/**********************************************************
461
435
*/
462
-
436
+
463
437
protected final Object deserializeWithView (JsonParser p , DeserializationContext ctxt ,
464
438
Object bean , Class <?> activeView )
465
439
throws IOException
466
440
{
467
- JsonToken t = p .getCurrentToken ();
468
- for (; t == JsonToken .FIELD_NAME ; t = p .nextToken ()) {
441
+ if (p .hasTokenId (JsonTokenId .ID_FIELD_NAME )) {
469
442
String propName = p .getCurrentName ();
470
- // Skip field name:
471
- p .nextToken ();
472
- SettableBeanProperty prop = _beanProperties .find (propName );
473
- if (prop != null ) {
474
- if (!prop .visibleInView (activeView )) {
475
- p .skipChildren ();
443
+ do {
444
+ p .nextToken ();
445
+ // TODO: 06-Jan-2015, tatu: try streamlining call sequences here as well
446
+ SettableBeanProperty prop = _beanProperties .find (propName );
447
+ if (prop != null ) {
448
+ if (!prop .visibleInView (activeView )) {
449
+ p .skipChildren ();
450
+ continue ;
451
+ }
452
+ try {
453
+ prop .deserializeAndSet (p , ctxt , bean );
454
+ } catch (Exception e ) {
455
+ wrapAndThrow (e , bean , propName , ctxt );
456
+ }
476
457
continue ;
477
458
}
478
- try {
479
- prop .deserializeAndSet (p , ctxt , bean );
480
- } catch (Exception e ) {
481
- wrapAndThrow (e , bean , propName , ctxt );
482
- }
483
- continue ;
484
- }
485
- handleUnknownVanilla (p , ctxt , bean , propName );
459
+ handleUnknownVanilla (p , ctxt , bean , propName );
460
+ } while ((propName = p .nextFieldName ()) != null );
486
461
}
487
462
return bean ;
488
463
}
0 commit comments