@@ -63,6 +63,7 @@ public class GenericConversionServiceTests {
63
63
64
64
private GenericConversionService conversionService = new GenericConversionService ();
65
65
66
+
66
67
@ Test
67
68
public void canConvert () {
68
69
assertFalse (conversionService .canConvert (String .class , Integer .class ));
@@ -750,6 +751,13 @@ public void testEnumToStringConversion() {
750
751
assertEquals ("A" , result );
751
752
}
752
753
754
+ @ Test
755
+ public void testSubclassOfEnumToString () throws Exception {
756
+ conversionService .addConverter (new EnumToStringConverter (conversionService ));
757
+ String result = conversionService .convert (EnumWithSubclass .FIRST , String .class );
758
+ assertEquals ("FIRST" , result );
759
+ }
760
+
753
761
@ Test
754
762
public void testEnumWithInterfaceToStringConversion () {
755
763
// SPR-9692
@@ -865,6 +873,7 @@ public void rawCollectionAsSource() throws Exception {
865
873
@ ExampleAnnotation
866
874
public String annotatedString ;
867
875
876
+
868
877
@ Retention (RetentionPolicy .RUNTIME )
869
878
public static @interface ExampleAnnotation {
870
879
}
@@ -907,8 +916,7 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
907
916
}
908
917
909
918
@ Override
910
- public Object convert (Object source , TypeDescriptor sourceType ,
911
- TypeDescriptor targetType ) {
919
+ public Object convert (Object source , TypeDescriptor sourceType , TypeDescriptor targetType ) {
912
920
return null ;
913
921
}
914
922
@@ -945,14 +953,19 @@ public int getNestedMatchAttempts() {
945
953
}
946
954
}
947
955
956
+
948
957
interface MyEnumBaseInterface {
958
+
949
959
String getBaseCode ();
950
960
}
951
961
962
+
952
963
interface MyEnumInterface extends MyEnumBaseInterface {
964
+
953
965
String getCode ();
954
966
}
955
967
968
+
956
969
public static enum MyEnum implements MyEnumInterface {
957
970
958
971
A ("1" ),
@@ -977,6 +990,17 @@ public String getBaseCode() {
977
990
}
978
991
979
992
993
+ public enum EnumWithSubclass {
994
+
995
+ FIRST {
996
+ @ Override
997
+ public String toString () {
998
+ return "1st" ;
999
+ }
1000
+ }
1001
+ }
1002
+
1003
+
980
1004
public static class MyStringToRawCollectionConverter implements Converter <String , Collection > {
981
1005
982
1006
@ Override
@@ -985,6 +1009,7 @@ public Collection convert(String source) {
985
1009
}
986
1010
}
987
1011
1012
+
988
1013
public static class MyStringToGenericCollectionConverter implements Converter <String , Collection <?>> {
989
1014
990
1015
@ Override
@@ -993,6 +1018,7 @@ public Collection<?> convert(String source) {
993
1018
}
994
1019
}
995
1020
1021
+
996
1022
private static class MyEnumInterfaceToStringConverter <T extends MyEnumInterface > implements Converter <T , String > {
997
1023
998
1024
@ Override
@@ -1001,6 +1027,7 @@ public String convert(T source) {
1001
1027
}
1002
1028
}
1003
1029
1030
+
1004
1031
private static class StringToMyEnumInterfaceConverterFactory implements ConverterFactory <String , MyEnumInterface > {
1005
1032
1006
1033
@ SuppressWarnings ("unchecked" )
@@ -1024,9 +1051,9 @@ public T convert(String source) {
1024
1051
return null ;
1025
1052
}
1026
1053
}
1027
-
1028
1054
}
1029
1055
1056
+
1030
1057
private static class StringToMyEnumBaseInterfaceConverterFactory implements ConverterFactory <String , MyEnumBaseInterface > {
1031
1058
1032
1059
@ SuppressWarnings ("unchecked" )
@@ -1050,7 +1077,6 @@ public T convert(String source) {
1050
1077
return null ;
1051
1078
}
1052
1079
}
1053
-
1054
1080
}
1055
1081
1056
1082
@@ -1062,6 +1088,7 @@ public Collection<String> convert(String source) {
1062
1088
}
1063
1089
}
1064
1090
1091
+
1065
1092
public static class MyStringToIntegerCollectionConverter implements Converter <String , Collection <Integer >> {
1066
1093
1067
1094
@ Override
0 commit comments