File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed
main/java/org/springframework/core/convert
test/java/org/springframework/core/convert Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2011 the original author or authors.
2
+ * Copyright 2002-2012 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
19
19
import java .lang .annotation .Annotation ;
20
20
21
+ import org .springframework .core .GenericCollectionTypeResolver ;
22
+
21
23
/**
22
24
* @author Keith Donald
25
+ * @author Phillip Webb
23
26
* @since 3.1
24
27
*/
25
28
class ClassDescriptor extends AbstractDescriptor {
@@ -34,18 +37,21 @@ public Annotation[] getAnnotations() {
34
37
}
35
38
36
39
@ Override
40
+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
37
41
protected Class <?> resolveCollectionElementType () {
38
- return null ;
42
+ return GenericCollectionTypeResolver . getCollectionType (( Class ) getType ()) ;
39
43
}
40
44
41
45
@ Override
46
+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
42
47
protected Class <?> resolveMapKeyType () {
43
- return null ;
48
+ return GenericCollectionTypeResolver . getMapKeyType (( Class ) getType ()) ;
44
49
}
45
50
46
51
@ Override
52
+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
47
53
protected Class <?> resolveMapValueType () {
48
- return null ;
54
+ return GenericCollectionTypeResolver . getMapValueType (( Class ) getType ()) ;
49
55
}
50
56
51
57
@ Override
Original file line number Diff line number Diff line change 24
24
import java .util .Collection ;
25
25
import java .util .Date ;
26
26
import java .util .HashMap ;
27
+ import java .util .HashSet ;
27
28
import java .util .List ;
28
29
import java .util .Map ;
29
30
@@ -818,4 +819,26 @@ public void testUpCastNotSuper() throws Exception {
818
819
}
819
820
}
820
821
822
+ @ Test
823
+ public void elementTypeForCollectionSubclass () throws Exception {
824
+ @ SuppressWarnings ("serial" )
825
+ class CustomSet extends HashSet <String > {
826
+ }
827
+
828
+ assertEquals (TypeDescriptor .valueOf (CustomSet .class ).getElementTypeDescriptor (), TypeDescriptor .valueOf (String .class ));
829
+ assertEquals (TypeDescriptor .forObject (new CustomSet ()).getElementTypeDescriptor (), TypeDescriptor .valueOf (String .class ));
830
+ }
831
+
832
+ @ Test
833
+ public void elementTypeForMapSubclass () throws Exception {
834
+ @ SuppressWarnings ("serial" )
835
+ class CustomMap extends HashMap <String , Integer > {
836
+ }
837
+
838
+ assertEquals (TypeDescriptor .valueOf (CustomMap .class ).getMapKeyTypeDescriptor (), TypeDescriptor .valueOf (String .class ));
839
+ assertEquals (TypeDescriptor .valueOf (CustomMap .class ).getMapValueTypeDescriptor (), TypeDescriptor .valueOf (Integer .class ));
840
+ assertEquals (TypeDescriptor .forObject (new CustomMap ()).getMapKeyTypeDescriptor (), TypeDescriptor .valueOf (String .class ));
841
+ assertEquals (TypeDescriptor .forObject (new CustomMap ()).getMapValueTypeDescriptor (), TypeDescriptor .valueOf (Integer .class ));
842
+ }
843
+
821
844
}
You can’t perform that action at this time.
0 commit comments