4
4
import java .lang .reflect .Constructor ;
5
5
import java .lang .reflect .InvocationTargetException ;
6
6
import java .util .*;
7
+ import java .util .concurrent .ConcurrentHashMap ;
7
8
8
9
import com .fasterxml .jackson .annotation .*;
9
10
@@ -177,8 +178,9 @@ public abstract class BeanDeserializerBase
177
178
* Note that this is <b>only needed</b> for polymorphic types,
178
179
* that is, when the actual type is not statically known.
179
180
* For other types this remains null.
181
+ * The map type changed in 2.18 (from HashMap to ConcurrentHashMap)
180
182
*/
181
- protected transient HashMap <ClassKey , JsonDeserializer <Object >> _subDeserializers ;
183
+ protected transient ConcurrentHashMap <ClassKey , JsonDeserializer <Object >> _subDeserializers ;
182
184
183
185
/**
184
186
* If one of properties has "unwrapped" value, we need separate
@@ -1882,17 +1884,14 @@ protected JsonDeserializer<Object> _findSubclassDeserializer(DeserializationCont
1882
1884
Object bean , TokenBuffer unknownTokens )
1883
1885
throws IOException
1884
1886
{
1885
- JsonDeserializer <Object > subDeser ;
1886
-
1887
1887
// First: maybe we have already created sub-type deserializer?
1888
- synchronized (this ) {
1889
- subDeser = (_subDeserializers == null ) ? null : _subDeserializers .get (new ClassKey (bean .getClass ()));
1890
- }
1888
+ final ClassKey classKey = new ClassKey (bean .getClass ());
1889
+ JsonDeserializer <Object > subDeser = (_subDeserializers == null ) ? null : _subDeserializers .get (classKey );
1891
1890
if (subDeser != null ) {
1892
1891
return subDeser ;
1893
1892
}
1894
1893
// If not, maybe we can locate one. First, need provider
1895
- JavaType type = ctxt .constructType (bean .getClass ());
1894
+ final JavaType type = ctxt .constructType (bean .getClass ());
1896
1895
/* 30-Jan-2012, tatu: Ideally we would be passing referring
1897
1896
* property; which in theory we could keep track of via
1898
1897
* ResolvableDeserializer (if we absolutely must...).
@@ -1902,12 +1901,14 @@ protected JsonDeserializer<Object> _findSubclassDeserializer(DeserializationCont
1902
1901
subDeser = ctxt .findRootValueDeserializer (type );
1903
1902
// Also, need to cache it
1904
1903
if (subDeser != null ) {
1905
- synchronized (this ) {
1906
- if (_subDeserializers == null ) {
1907
- _subDeserializers = new HashMap <ClassKey ,JsonDeserializer <Object >>();;
1904
+ if (_subDeserializers == null ) {
1905
+ synchronized (this ) {
1906
+ if (_subDeserializers == null ) {
1907
+ _subDeserializers = new ConcurrentHashMap <>();
1908
+ }
1908
1909
}
1909
- _subDeserializers .put (new ClassKey (bean .getClass ()), subDeser );
1910
1910
}
1911
+ _subDeserializers .put (classKey , subDeser );
1911
1912
}
1912
1913
return subDeser ;
1913
1914
}
0 commit comments