You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java
+14-6Lines changed: 14 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,12 @@ public interface ConversionService {
27
27
28
28
/**
29
29
* Returns true if objects of sourceType can be converted to targetType.
30
-
* @param sourceType the source type to convert from (required)
30
+
* If this method returns true, it means {@link #convert(Object, Class)} is capable of converting an instance of sourceType to targetType.
31
+
* Special note on collections, arrays, and maps types:
32
+
* For conversion between collection, array, and map types, this method will return 'true'
33
+
* even though a convert invocation may still generate a {@link ConversionException} if the underlying elements are not convertible.
34
+
* Callers are expected to handle this exceptional case when working with collections and maps.
35
+
* @param sourceType the source type to convert from (may be null if source is null)
31
36
* @param targetType the target type to convert to (required)
32
37
* @return true if a conversion can be performed, false if not
33
38
* @throws IllegalArgumentException if targetType is null
@@ -36,12 +41,16 @@ public interface ConversionService {
36
41
37
42
/**
38
43
* Returns true if objects of sourceType can be converted to the targetType.
39
-
* The TypeDescriptors provide additional context about the source and target locations where conversion would occur, often object property locations.
40
-
* @param sourceType context about the source type to convert from (required)
44
+
* The TypeDescriptors provide additional context about the source and target locations where conversion would occur, often object fields or property locations.
45
+
* If this method returns true, it means {@link #convert(Object, TypeDescriptor, TypeDescriptor)} is capable of converting an instance of sourceType to targetType.
46
+
* Special note on collections, arrays, and maps types:
47
+
* For conversion between collection, array, and map types, this method will return 'true'
48
+
* even though a convert invocation may still generate a {@link ConversionException} if the underlying elements are not convertible.
49
+
* Callers are expected to handle this exceptional case when working with collections and maps.
50
+
* @param sourceType context about the source type to convert from (may be null if source is null)
41
51
* @param targetType context about the target type to convert to (required)
42
52
* @return true if a conversion can be performed between the source and target types, false if not
43
53
* @throws IllegalArgumentException if targetType is null
@@ -57,15 +66,14 @@ public interface ConversionService {
57
66
58
67
/**
59
68
* Convert the source to targetType.
60
-
* The TypeDescriptors provide additional context about the source and target locations where conversion will occur, often object property locations.
69
+
* The TypeDescriptors provide additional context about the source and target locations where conversion will occur, often object fields or property locations.
61
70
* @param source the source object to convert (may be null)
62
71
* @param sourceType context about the source type converting from (may be null if source is null)
63
72
* @param targetType context about the target type to convert to (required)
64
73
* @return the converted object, an instance of {@link TypeDescriptor#getObjectType() targetType}</code>
65
74
* @throws ConversionException if a conversion exception occurred
66
75
* @throws IllegalArgumentException if targetType is null
67
76
* @throws IllegalArgumentException if sourceType is null but source is not null
Copy file name to clipboardExpand all lines: org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java
Copy file name to clipboardExpand all lines: org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,7 @@
28
28
29
29
/**
30
30
* Converts a comma-delimited String to a Collection.
31
+
* If the target collection element type is declared, only matches if String.class can be converted to it.
31
32
*
32
33
* @author Keith Donald
33
34
* @since 3.0
@@ -45,10 +46,11 @@ public Set<ConvertiblePair> getConvertibleTypes() {
Copy file name to clipboardExpand all lines: org.springframework.core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -759,4 +759,5 @@ public static TestEntity findTestEntity(Long id) {
Copy file name to clipboardExpand all lines: org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java
+23-1Lines changed: 23 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -16,16 +16,17 @@
16
16
17
17
packageorg.springframework.core.convert.support;
18
18
19
+
importstaticjunit.framework.Assert.assertTrue;
19
20
importstaticorg.junit.Assert.assertEquals;
20
21
importstaticorg.junit.Assert.assertFalse;
21
22
importstaticorg.junit.Assert.assertNotNull;
22
23
importstaticorg.junit.Assert.assertNull;
23
24
importstaticorg.junit.Assert.assertSame;
24
-
importstaticorg.junit.Assert.assertTrue;
25
25
importstaticorg.junit.Assert.fail;
26
26
27
27
importjava.util.ArrayList;
28
28
importjava.util.Arrays;
29
+
importjava.util.Collection;
29
30
importjava.util.HashMap;
30
31
importjava.util.LinkedHashMap;
31
32
importjava.util.LinkedList;
@@ -528,4 +529,25 @@ public WithCopyConstructor(WithCopyConstructor value) {
0 commit comments