@@ -52,22 +52,14 @@ private synchronized static Decoder gen(String cacheKey, Type type) {
5252 return decoder ;
5353 }
5454 }
55- Type [] typeArgs = new Type [0 ];
56- Class clazz ;
57- if (type instanceof ParameterizedType ) {
58- ParameterizedType pType = (ParameterizedType ) type ;
59- clazz = (Class ) pType .getRawType ();
60- typeArgs = pType .getActualTypeArguments ();
61- } else {
62- clazz = (Class ) type ;
63- }
64- decoder = CodegenImplNative .NATIVE_DECODERS .get (clazz );
55+ ClassInfo classInfo = new ClassInfo (type );
56+ decoder = CodegenImplNative .NATIVE_DECODERS .get (classInfo .clazz );
6557 if (decoder != null ) {
6658 return decoder ;
6759 }
6860 addPlaceholderDecoderToSupportRecursiveStructure (cacheKey );
6961 if (mode == DecodingMode .REFLECTION_MODE ) {
70- decoder = ReflectionDecoderFactory .create (clazz , typeArgs );
62+ decoder = ReflectionDecoderFactory .create (classInfo );
7163 JsoniterSpi .addNewDecoder (cacheKey , decoder );
7264 return decoder ;
7365 }
@@ -82,7 +74,7 @@ private synchronized static Decoder gen(String cacheKey, Type type) {
8274 }
8375 }
8476 }
85- String source = genSource (clazz , typeArgs );
77+ String source = genSource (classInfo );
8678 source = "public static java.lang.Object decode_(com.jsoniter.JsonIterator iter) throws java.io.IOException { "
8779 + source + "}" ;
8880 if ("true" .equals (System .getenv ("JSONITER_DEBUG" ))) {
@@ -99,7 +91,7 @@ private synchronized static Decoder gen(String cacheKey, Type type) {
9991 JsoniterSpi .addNewDecoder (cacheKey , decoder );
10092 return decoder ;
10193 } catch (Exception e ) {
102- String msg = "failed to generate decoder for: " + type + " with " + Arrays .toString (typeArgs ) + ", exception: " + e ;
94+ String msg = "failed to generate decoder for: " + classInfo + " with " + Arrays .toString (classInfo . typeArgs ) + ", exception: " + e ;
10395 msg = msg + "\n " + source ;
10496 throw new JsonException (msg , e );
10597 }
@@ -218,24 +210,24 @@ private static void createDir(String cacheKey) {
218210 }
219211 }
220212
221- private static String genSource (Class clazz , Type [] typeArgs ) {
222- if (clazz .isArray ()) {
223- return CodegenImplArray .genArray (clazz );
213+ private static String genSource (ClassInfo classInfo ) {
214+ if (classInfo . clazz .isArray ()) {
215+ return CodegenImplArray .genArray (classInfo );
224216 }
225- if (Map .class .isAssignableFrom (clazz )) {
226- return CodegenImplMap .genMap (clazz , typeArgs );
217+ if (Map .class .isAssignableFrom (classInfo . clazz )) {
218+ return CodegenImplMap .genMap (classInfo );
227219 }
228- if (Collection .class .isAssignableFrom (clazz )) {
229- return CodegenImplArray .genCollection (clazz , typeArgs );
220+ if (Collection .class .isAssignableFrom (classInfo . clazz )) {
221+ return CodegenImplArray .genCollection (classInfo );
230222 }
231- if (clazz .isEnum ()) {
232- return CodegenImplEnum .genEnum (clazz );
223+ if (classInfo . clazz .isEnum ()) {
224+ return CodegenImplEnum .genEnum (classInfo );
233225 }
234- ClassDescriptor desc = ClassDescriptor .getDecodingClassDescriptor (clazz , false );
226+ ClassDescriptor desc = ClassDescriptor .getDecodingClassDescriptor (classInfo , false );
235227 if (shouldUseStrictMode (desc )) {
236- return CodegenImplObjectStrict .genObjectUsingStrict (clazz , desc );
228+ return CodegenImplObjectStrict .genObjectUsingStrict (desc );
237229 } else {
238- return CodegenImplObjectHash .genObjectUsingHash (clazz , desc );
230+ return CodegenImplObjectHash .genObjectUsingHash (desc );
239231 }
240232 }
241233
0 commit comments