1
1
package com .fasterxml .jackson .databind .jsontype .impl ;
2
2
3
3
import java .io .IOException ;
4
- import java .util .HashMap ;
4
+ import java .util .Map ;
5
+ import java .util .concurrent .ConcurrentHashMap ;
5
6
6
7
import com .fasterxml .jackson .annotation .JsonTypeInfo ;
7
8
import com .fasterxml .jackson .core .*;
@@ -55,7 +56,7 @@ public abstract class TypeDeserializerBase
55
56
* For efficient operation we will lazily build mappings from type ids
56
57
* to actual deserializers, once needed.
57
58
*/
58
- protected final HashMap <String ,JsonDeserializer <Object >> _deserializers ;
59
+ protected final Map <String ,JsonDeserializer <Object >> _deserializers ;
59
60
60
61
protected JsonDeserializer <Object > _defaultImplDeserializer ;
61
62
@@ -72,7 +73,7 @@ protected TypeDeserializerBase(JavaType baseType, TypeIdResolver idRes,
72
73
_idResolver = idRes ;
73
74
_typePropertyName = typePropertyName ;
74
75
_typeIdVisible = typeIdVisible ;
75
- _deserializers = new HashMap <String ,JsonDeserializer <Object >>();
76
+ _deserializers = new ConcurrentHashMap <String , JsonDeserializer <Object >>();
76
77
if (defaultImpl == null ) {
77
78
_defaultImpl = null ;
78
79
} else {
@@ -144,39 +145,35 @@ public String toString()
144
145
protected final JsonDeserializer <Object > _findDeserializer (DeserializationContext ctxt , String typeId )
145
146
throws IOException
146
147
{
147
- JsonDeserializer <Object > deser ;
148
-
149
- synchronized (_deserializers ) {
150
- deser = _deserializers .get (typeId );
151
- if (deser == null ) {
152
- /* As per [Databind#305], need to provide contextual info. But for
153
- * backwards compatibility, let's start by only supporting this
154
- * for base class, not via interface. Later on we can add this
155
- * to the interface, assuming deprecation at base class helps.
148
+ JsonDeserializer <Object > deser = _deserializers .get (typeId );
149
+ if (deser == null ) {
150
+ /* As per [Databind#305], need to provide contextual info. But for
151
+ * backwards compatibility, let's start by only supporting this
152
+ * for base class, not via interface. Later on we can add this
153
+ * to the interface, assuming deprecation at base class helps.
154
+ */
155
+ JavaType type = _idResolver .typeFromId (ctxt , typeId );
156
+ if (type == null ) {
157
+ // As per [JACKSON-614], use the default impl if no type id available:
158
+ deser = _findDefaultImplDeserializer (ctxt );
159
+ if (deser == null ) {
160
+ deser = _handleUnknownTypeId (ctxt , typeId , _idResolver , _baseType );
161
+ }
162
+ } else {
163
+ /* 16-Dec-2010, tatu: Since nominal type we get here has no (generic) type parameters,
164
+ * we actually now need to explicitly narrow from base type (which may have parameterization)
165
+ * using raw type.
166
+ *
167
+ * One complication, though; can not change 'type class' (simple type to container); otherwise
168
+ * we may try to narrow a SimpleType (Object.class) into MapType (Map.class), losing actual
169
+ * type in process (getting SimpleType of Map.class which will not work as expected)
156
170
*/
157
- JavaType type = _idResolver .typeFromId (ctxt , typeId );
158
- if (type == null ) {
159
- // As per [JACKSON-614], use the default impl if no type id available:
160
- deser = _findDefaultImplDeserializer (ctxt );
161
- if (deser == null ) {
162
- deser = _handleUnknownTypeId (ctxt , typeId , _idResolver , _baseType );
163
- }
164
- } else {
165
- /* 16-Dec-2010, tatu: Since nominal type we get here has no (generic) type parameters,
166
- * we actually now need to explicitly narrow from base type (which may have parameterization)
167
- * using raw type.
168
- *
169
- * One complication, though; can not change 'type class' (simple type to container); otherwise
170
- * we may try to narrow a SimpleType (Object.class) into MapType (Map.class), losing actual
171
- * type in process (getting SimpleType of Map.class which will not work as expected)
172
- */
173
- if (_baseType != null && _baseType .getClass () == type .getClass ()) {
174
- type = _baseType .narrowBy (type .getRawClass ());
175
- }
176
- deser = ctxt .findContextualValueDeserializer (type , _property );
171
+ if (_baseType != null && _baseType .getClass () == type .getClass ()) {
172
+ type = _baseType .narrowBy (type .getRawClass ());
177
173
}
178
- _deserializers . put ( typeId , deser );
174
+ deser = ctxt . findContextualValueDeserializer ( type , _property );
179
175
}
176
+ _deserializers .put (typeId , deser );
180
177
}
181
178
return deser ;
182
179
}
0 commit comments