1515
1616public class JsonIterator implements Closeable {
1717
18+ public Config configCache ;
1819 private static boolean isStreamingEnabled = false ;
1920 final static ValueType [] valueTypes = new ValueType [256 ];
2021 InputStream in ;
@@ -305,12 +306,20 @@ public final <T> T read(T existingObject) throws IOException {
305306 try {
306307 this .existingObject = existingObject ;
307308 Class <?> clazz = existingObject .getClass ();
308- return (T ) Codegen .getDecoder (TypeLiteral .create (clazz ).getDecoderCacheKey (), clazz ).decode (this );
309+ String cacheKey = currentConfig ().getDecoderCacheKey (clazz );
310+ return (T ) Codegen .getDecoder (cacheKey , clazz ).decode (this );
309311 } catch (ArrayIndexOutOfBoundsException e ) {
310312 throw reportError ("read" , "premature end" );
311313 }
312314 }
313315
316+ private Config currentConfig () {
317+ if (configCache == null ) {
318+ configCache = JsoniterSpi .getCurrentConfig ();
319+ }
320+ return configCache ;
321+ }
322+
314323 /**
315324 * try to bind to existing object, returned object might not the same instance
316325 *
@@ -323,15 +332,17 @@ public final <T> T read(T existingObject) throws IOException {
323332 public final <T > T read (TypeLiteral <T > typeLiteral , T existingObject ) throws IOException {
324333 try {
325334 this .existingObject = existingObject ;
326- return (T ) Codegen .getDecoder (typeLiteral .getDecoderCacheKey (), typeLiteral .getType ()).decode (this );
335+ String cacheKey = currentConfig ().getDecoderCacheKey (typeLiteral .getType ());
336+ return (T ) Codegen .getDecoder (cacheKey , typeLiteral .getType ()).decode (this );
327337 } catch (ArrayIndexOutOfBoundsException e ) {
328338 throw reportError ("read" , "premature end" );
329339 }
330340 }
331341
332342 public final <T > T read (Class <T > clazz ) throws IOException {
333343 try {
334- return (T ) Codegen .getDecoder (TypeLiteral .create (clazz ).getDecoderCacheKey (), clazz ).decode (this );
344+ String cacheKey = currentConfig ().getDecoderCacheKey (clazz );
345+ return (T ) Codegen .getDecoder (cacheKey , clazz ).decode (this );
335346 } catch (ArrayIndexOutOfBoundsException e ) {
336347 throw reportError ("read" , "premature end" );
337348 }
0 commit comments