66import tools .jackson .databind .*;
77import tools .jackson .databind .jsontype .TypeDeserializer ;
88import tools .jackson .databind .jsontype .TypeIdResolver ;
9+ import tools .jackson .databind .util .ClassUtil ;
910
1011/**
1112 * Special {@link TypeDeserializer} implementation used to explicitly
2223public class NoOpTypeDeserializer extends TypeDeserializer
2324{
2425 private final JavaType _baseType ;
25- private final ValueDeserializer < Object > _deserializer ;
26+ private final BeanProperty _property ;
2627
27- public NoOpTypeDeserializer (JavaType baseType , ValueDeserializer <Object > deser ) {
28+ // Dynamically constructed deserializer
29+ private volatile ValueDeserializer <Object > _deserializer ;
30+
31+ private NoOpTypeDeserializer (JavaType baseType , BeanProperty prop ) {
2832 _baseType = baseType ;
29- _deserializer = deser ;
33+ _property = prop ;
3034 }
3135
32- public NoOpTypeDeserializer withDeserializer (ValueDeserializer <Object > deser ) {
33- if (_deserializer == deser ) {
34- return this ;
35- }
36- return new NoOpTypeDeserializer (_baseType , deser );
36+ public static NoOpTypeDeserializer forBaseType (DeserializationContext ctxt ,
37+ JavaType baseType ) {
38+ return new NoOpTypeDeserializer (baseType , null );
3739 }
3840
3941 @ Override
4042 public TypeDeserializer forProperty (BeanProperty prop ) {
41- return this ;
43+ if (_property == prop ) {
44+ return this ;
45+ }
46+ return new NoOpTypeDeserializer (_baseType , prop );
4247 }
4348
4449 @ Override
@@ -63,34 +68,30 @@ public Class<?> getDefaultImpl() {
6368 }
6469
6570 @ Override
66- public Object deserializeTypedFromObject (JsonParser p ,
67- DeserializationContext ctxt ) throws JacksonException
71+ public Object deserializeTypedFromObject (JsonParser p , DeserializationContext ctxt )
72+ throws JacksonException
6873 {
69- // Just deserialize without type info
7074 return _deserialize (p , ctxt );
7175 }
7276
7377 @ Override
74- public Object deserializeTypedFromArray (JsonParser p ,
75- DeserializationContext ctxt ) throws JacksonException
78+ public Object deserializeTypedFromArray (JsonParser p , DeserializationContext ctxt )
79+ throws JacksonException
7680 {
77- // Just deserialize without type info
7881 return _deserialize (p , ctxt );
7982 }
8083
8184 @ Override
82- public Object deserializeTypedFromScalar (JsonParser p ,
83- DeserializationContext ctxt ) throws JacksonException
85+ public Object deserializeTypedFromScalar (JsonParser p , DeserializationContext ctxt )
86+ throws JacksonException
8487 {
85- // Just deserialize without type info
8688 return _deserialize (p , ctxt );
8789 }
8890
8991 @ Override
90- public Object deserializeTypedFromAny (JsonParser p ,
91- DeserializationContext ctxt ) throws JacksonException
92+ public Object deserializeTypedFromAny (JsonParser p , DeserializationContext ctxt )
93+ throws JacksonException
9294 {
93- // Just deserialize without type info
9495 return _deserialize (p , ctxt );
9596 }
9697
@@ -99,14 +100,16 @@ protected Object _deserialize(JsonParser p, DeserializationContext ctxt)
99100 {
100101 ValueDeserializer <Object > deser = _deserializer ;
101102
102- // Find deserializer for the base type (this will find custom deserializers
103- // registered for this type, including those from @JsonDeserialize annotations)
103+ // Find deserializer for the base type, given property (if any).
104+ // This will find custom deserializers registered for this type,
105+ // including those from @JsonDeserialize annotations)
104106 if (deser == null ) {
105- deser = ctxt .findContextualValueDeserializer (_baseType , null );
107+ deser = ctxt .findContextualValueDeserializer (_baseType , _property );
106108 if (deser == null ) {
107109 ctxt .reportBadDefinition (_baseType ,
108- "Cannot find deserializer for type " + _baseType );
110+ "Cannot find deserializer for type " +ClassUtil . getTypeDescription ( _baseType ) );
109111 }
112+ _deserializer = deser ;
110113 }
111114 return deser .deserialize (p , ctxt );
112115 }
0 commit comments