|
31 | 31 | import org.springframework.core.convert.ConverterNotFoundException;
|
32 | 32 | import org.springframework.core.convert.TypeDescriptor;
|
33 | 33 | import org.springframework.core.convert.converter.Converter;
|
| 34 | +import org.springframework.core.io.Resource; |
| 35 | +import org.springframework.core.io.DescriptiveResource; |
34 | 36 | import org.springframework.util.StopWatch;
|
35 | 37 | import org.springframework.util.StringUtils;
|
36 | 38 |
|
@@ -217,6 +219,16 @@ public void testObjectArrayToStringArray() {
|
217 | 219 | assertEquals("RESULT", converted[0]);
|
218 | 220 | }
|
219 | 221 |
|
| 222 | + @Test |
| 223 | + public void testStringArrayToResourceArray() { |
| 224 | + GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); |
| 225 | + conversionService.addConverter(new MyStringArrayToResourceArrayConverter()); |
| 226 | + Resource[] converted = conversionService.convert(new String[] {"x1", "z3"}, Resource[].class); |
| 227 | + assertEquals(2, converted.length); |
| 228 | + assertEquals("1", converted[0].getDescription()); |
| 229 | + assertEquals("3", converted[1].getDescription()); |
| 230 | + } |
| 231 | + |
220 | 232 | @Test
|
221 | 233 | public void testStringArrayToIntegerArray() {
|
222 | 234 | GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
|
@@ -393,6 +405,18 @@ public String convert(MyBaseInterface source) {
|
393 | 405 | }
|
394 | 406 |
|
395 | 407 |
|
| 408 | + private static class MyStringArrayToResourceArrayConverter implements Converter<String[], Resource[]> { |
| 409 | + |
| 410 | + public Resource[] convert(String[] source) { |
| 411 | + Resource[] result = new Resource[source.length]; |
| 412 | + for (int i = 0; i < source.length; i++) { |
| 413 | + result[i] = new DescriptiveResource(source[i].substring(1)); |
| 414 | + } |
| 415 | + return result; |
| 416 | + } |
| 417 | + } |
| 418 | + |
| 419 | + |
396 | 420 | private static class MyStringArrayToIntegerArrayConverter implements Converter<String[], Integer[]> {
|
397 | 421 |
|
398 | 422 | public Integer[] convert(String[] source) {
|
|
0 commit comments