@@ -12,6 +12,7 @@ public class JsoniterConfig extends EmptyExtension implements Config {
1212 private final String configName ;
1313 private final Builder builder ;
1414 private volatile Map <Type , String > decoderCacheKeys = new HashMap <Type , String >();
15+ private volatile Map <Type , String > encoderCacheKeys = new HashMap <Type , String >();
1516
1617 public JsoniterConfig (Builder builder ) {
1718 this .configName = JsoniterSpi .assignConfigName (builder );
@@ -37,6 +38,26 @@ public String getDecoderCacheKey(Type type) {
3738 cacheKey = TypeLiteral .create (type ).getDecoderCacheKey (configName );
3839 HashMap <Type , String > newCache = new HashMap <Type , String >(decoderCacheKeys );
3940 newCache .put (type , cacheKey );
41+ decoderCacheKeys = newCache ;
42+ return cacheKey ;
43+ }
44+ }
45+
46+ @ Override
47+ public String getEncoderCacheKey (Type type ) {
48+ String cacheKey = encoderCacheKeys .get (type );
49+ if (cacheKey != null ) {
50+ return cacheKey ;
51+ }
52+ synchronized (this ) {
53+ cacheKey = encoderCacheKeys .get (type );
54+ if (cacheKey != null ) {
55+ return cacheKey ;
56+ }
57+ cacheKey = TypeLiteral .create (type ).getEncoderCacheKey (configName );
58+ HashMap <Type , String > newCache = new HashMap <Type , String >(encoderCacheKeys );
59+ newCache .put (type , cacheKey );
60+ encoderCacheKeys = newCache ;
4061 return cacheKey ;
4162 }
4263 }
0 commit comments