@@ -381,6 +381,24 @@ public JavaType[] findTypeParameters(JavaType type, Class<?> expType)
381
381
return findTypeParameters (raw , expType , new TypeBindings (this , type ));
382
382
}
383
383
384
+ /**
385
+ * @since 2.7
386
+ */
387
+ public JavaType [] findTypeParameters (JavaType type , Class <?> expType , TypeBindings bindings )
388
+ {
389
+ if (expType == type .getParameterSource ()) {
390
+ int count = type .containedTypeCount ();
391
+ if (count == 0 ) return null ;
392
+ JavaType [] result = new JavaType [count ];
393
+ for (int i = 0 ; i < count ; ++i ) {
394
+ result [i ] = type .containedType (i );
395
+ }
396
+ return result ;
397
+ }
398
+ Class <?> raw = type .getRawClass ();
399
+ return findTypeParameters (raw , expType , bindings );
400
+ }
401
+
384
402
public JavaType [] findTypeParameters (Class <?> clz , Class <?> expType ) {
385
403
return findTypeParameters (clz , expType , new TypeBindings (this , clz ));
386
404
}
@@ -1003,6 +1021,8 @@ protected JavaType _fromParamType(ParameterizedType type, TypeBindings context)
1003
1021
if (Map .class .isAssignableFrom (rawType )) {
1004
1022
// 19-Mar-2015, tatu: Looks like 2nd arg ought to be Map.class, but that causes fails
1005
1023
JavaType subtype = constructSimpleType (rawType , rawType , pt );
1024
+ // 23-Sep-2015, tatu: and why do we not pass 3rd arg of 'context'? Won't help, it seems,
1025
+ // plus causes other issues. Sigh.
1006
1026
JavaType [] mapParams = findTypeParameters (subtype , Map .class );
1007
1027
if (mapParams .length != 2 ) {
1008
1028
throw new IllegalArgumentException ("Could not find 2 type parameters for Map class " +rawType .getName ()+" (found " +mapParams .length +")" );
@@ -1027,8 +1047,9 @@ protected JavaType _fromParamType(ParameterizedType type, TypeBindings context)
1027
1047
rt = pt [0 ];
1028
1048
}
1029
1049
} else {
1030
- JavaType [] pts = findTypeParameters (rawType , AtomicReference .class );
1031
- if (pts != null && pts .length != 1 ) {
1050
+ JavaType subtype = constructSimpleType (rawType , rawType , pt );
1051
+ JavaType [] pts = findTypeParameters (subtype , AtomicReference .class , context );
1052
+ if (pts != null && pts .length == 1 ) {
1032
1053
rt = pts [0 ];
1033
1054
}
1034
1055
}
@@ -1043,8 +1064,11 @@ protected JavaType _fromParamType(ParameterizedType type, TypeBindings context)
1043
1064
vt = pt [1 ];
1044
1065
}
1045
1066
} else {
1046
- JavaType [] pts = findTypeParameters (rawType , Map .Entry .class );
1047
- if (pts != null && pts .length != 2 ) {
1067
+ // 23-Sep-2015, tatu: Must be careful here; type resolution can NOT be done
1068
+ // directly quite yet. Instead, need to do indirectly...
1069
+ JavaType subtype = constructSimpleType (rawType , rawType , pt );
1070
+ JavaType [] pts = findTypeParameters (subtype , Map .Entry .class , context );
1071
+ if (pts != null && pts .length == 2 ) {
1048
1072
kt = pts [0 ];
1049
1073
vt = pts [1 ];
1050
1074
}
0 commit comments