@@ -20,20 +20,13 @@ public class BeanDeserializer
2020{
2121 /* TODOs for future versions:
2222 *
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?
3624 *
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)
3730 */
3831
3932 private static final long serialVersionUID = 1L ;
@@ -47,8 +40,7 @@ public class BeanDeserializer
4740 /**
4841 * Constructor used by {@link BeanDeserializerBuilder}.
4942 */
50- public BeanDeserializer (BeanDeserializerBuilder builder ,
51- BeanDescription beanDesc ,
43+ public BeanDeserializer (BeanDeserializerBuilder builder , BeanDescription beanDesc ,
5244 BeanPropertyMap properties , Map <String , SettableBeanProperty > backRefs ,
5345 HashSet <String > ignorableProps , boolean ignoreAllUnknown ,
5446 boolean hasViews )
@@ -126,12 +118,10 @@ protected BeanDeserializerBase asArrayDeserializer() {
126118 * like Afterburner change definition.
127119 */
128120 @ Override
129- public Object deserialize (JsonParser p , DeserializationContext ctxt )
130- throws IOException
121+ public Object deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException
131122 {
132- JsonToken t = p .getCurrentToken ();
133123 // common case first
134- if (t == JsonToken . START_OBJECT ) { // TODO: in 2.6, use 'p.hasTokenId()'
124+ if (p . isExpectedStartObjectToken ()) {
135125 if (_vanillaProcessing ) {
136126 return vanillaDeserialize (p , ctxt , p .nextToken ());
137127 }
@@ -141,6 +131,7 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt)
141131 }
142132 return deserializeFromObject (p , ctxt );
143133 }
134+ JsonToken t = p .getCurrentToken ();
144135 return _deserializeOther (p , ctxt , t );
145136 }
146137
@@ -177,9 +168,7 @@ protected final Object _deserializeOther(JsonParser p, DeserializationContext ct
177168 }
178169 }
179170
180- protected Object _missingToken (JsonParser p , DeserializationContext ctxt )
181- throws JsonProcessingException
182- {
171+ protected Object _missingToken (JsonParser p , DeserializationContext ctxt ) throws IOException {
183172 throw ctxt .endOfInputException (handledType ());
184173 }
185174
@@ -189,8 +178,7 @@ protected Object _missingToken(JsonParser p, DeserializationContext ctxt)
189178 * after collecting some or all of the properties to set.
190179 */
191180 @ 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
194182 {
195183 // [databind#631]: Assign current value, to be accessible by custom serializers
196184 p .setCurrentValue (bean );
@@ -203,24 +191,33 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt, Object bean
203191 if (_externalTypeIdHandler != null ) {
204192 return deserializeWithExternalTypeId (p , ctxt , bean );
205193 }
206- JsonToken t = p .getCurrentToken ();
194+ String propName ;
195+
207196 // 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+ }
210208 }
211209 if (_needViewProcesing ) {
212210 Class <?> view = ctxt .getActiveView ();
213211 if (view != null ) {
214212 return deserializeWithView (p , ctxt , bean , view );
215213 }
216214 }
217- for (; t == JsonToken .FIELD_NAME ; t = p .nextToken ()) {
218- String propName = p .getCurrentName ();
215+ do {
219216 p .nextToken ();
220217 if (!_beanProperties .findDeserializeAndSet (p , ctxt , bean , propName )) {
221218 handleUnknownVanilla (p , ctxt , bean , propName );
222219 }
223- }
220+ } while (( propName = p . nextFieldName ()) != null );
224221 return bean ;
225222 }
226223
@@ -241,17 +238,6 @@ private final Object vanillaDeserialize(JsonParser p,
241238 final Object bean = _valueInstantiator .createUsingDefault (ctxt );
242239 // [databind#631]: Assign current value, to be accessible by custom serializers
243240 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- /*
255241 if (p .hasTokenId (JsonTokenId .ID_FIELD_NAME )) {
256242 String propName = p .getCurrentName ();
257243 do {
@@ -261,7 +247,6 @@ private final Object vanillaDeserialize(JsonParser p,
261247 }
262248 } while ((propName = p .nextFieldName ()) != null );
263249 }
264- */
265250 return bean ;
266251 }
267252
@@ -280,7 +265,7 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t
280265 */
281266 if (_objectIdReader != null && _objectIdReader .maySerializeAsObject ()) {
282267 // TODO: in 2.6, use 'p.hasTokenId()'
283- if (( p . getCurrentTokenId () == JsonTokenId .ID_FIELD_NAME )
268+ if (p . hasTokenId ( JsonTokenId .ID_FIELD_NAME )
284269 && _objectIdReader .isValidReferencePropertyName (p .getCurrentName (), p )) {
285270 return deserializeFromObjectId (p , ctxt );
286271 }
@@ -328,16 +313,6 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t
328313 return deserializeWithView (p , ctxt , bean , view );
329314 }
330315 }
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- /*
341316 if (p .hasTokenId (JsonTokenId .ID_FIELD_NAME )) {
342317 String propName = p .getCurrentName ();
343318 do {
@@ -347,7 +322,6 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t
347322 }
348323 } while ((propName = p .nextFieldName ()) != null );
349324 }
350- */
351325 return bean ;
352326 }
353327
@@ -459,30 +433,31 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
459433 /* Deserializing when we have to consider an active View
460434 /**********************************************************
461435 */
462-
436+
463437 protected final Object deserializeWithView (JsonParser p , DeserializationContext ctxt ,
464438 Object bean , Class <?> activeView )
465439 throws IOException
466440 {
467- JsonToken t = p .getCurrentToken ();
468- for (; t == JsonToken .FIELD_NAME ; t = p .nextToken ()) {
441+ if (p .hasTokenId (JsonTokenId .ID_FIELD_NAME )) {
469442 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+ }
476457 continue ;
477458 }
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 );
486461 }
487462 return bean ;
488463 }
0 commit comments