@@ -15,17 +15,6 @@ class Codegen {
1515 // only read/write when generating code with synchronized protection
1616 private final static Set <String > generatedClassNames = new HashSet <String >();
1717 static CodegenAccess .StaticCodegenTarget isDoingStaticCodegen = null ;
18- static DecodingMode mode = DecodingMode .REFLECTION_MODE ;
19- static {
20- String envMode = System .getenv ("JSONITER_DECODING_MODE" );
21- if (envMode != null ) {
22- mode = DecodingMode .valueOf (envMode );
23- }
24- }
25-
26- public static void setMode (DecodingMode mode ) {
27- Codegen .mode = mode ;
28- }
2918
3019 static Decoder getDecoder (String cacheKey , Type type ) {
3120 Decoder decoder = JsoniterSpi .getDecoder (cacheKey );
@@ -58,6 +47,8 @@ private synchronized static Decoder gen(String cacheKey, Type type) {
5847 return decoder ;
5948 }
6049 addPlaceholderDecoderToSupportRecursiveStructure (cacheKey );
50+ Config currentConfig = JsoniterSpi .getCurrentConfig ();
51+ DecodingMode mode = currentConfig .decodingMode ();
6152 if (mode == DecodingMode .REFLECTION_MODE ) {
6253 decoder = ReflectionDecoderFactory .create (classInfo );
6354 JsoniterSpi .addNewDecoder (cacheKey , decoder );
@@ -74,7 +65,7 @@ private synchronized static Decoder gen(String cacheKey, Type type) {
7465 }
7566 }
7667 }
77- String source = genSource (classInfo );
68+ String source = genSource (mode , classInfo );
7869 source = "public static java.lang.Object decode_(com.jsoniter.JsonIterator iter) throws java.io.IOException { "
7970 + source + "}" ;
8071 if ("true" .equals (System .getenv ("JSONITER_DEBUG" ))) {
@@ -210,7 +201,7 @@ private static void createDir(String cacheKey) {
210201 }
211202 }
212203
213- private static String genSource (ClassInfo classInfo ) {
204+ private static String genSource (DecodingMode mode , ClassInfo classInfo ) {
214205 if (classInfo .clazz .isArray ()) {
215206 return CodegenImplArray .genArray (classInfo );
216207 }
@@ -224,14 +215,14 @@ private static String genSource(ClassInfo classInfo) {
224215 return CodegenImplEnum .genEnum (classInfo );
225216 }
226217 ClassDescriptor desc = ClassDescriptor .getDecodingClassDescriptor (classInfo , false );
227- if (shouldUseStrictMode (desc )) {
218+ if (shouldUseStrictMode (mode , desc )) {
228219 return CodegenImplObjectStrict .genObjectUsingStrict (desc );
229220 } else {
230221 return CodegenImplObjectHash .genObjectUsingHash (desc );
231222 }
232223 }
233224
234- private static boolean shouldUseStrictMode (ClassDescriptor desc ) {
225+ private static boolean shouldUseStrictMode (DecodingMode mode , ClassDescriptor desc ) {
235226 if (mode == DecodingMode .DYNAMIC_MODE_AND_MATCH_FIELD_STRICTLY ) {
236227 return true ;
237228 }
0 commit comments