|
14 | 14 | * Internal API for converting arguments of type {@link String} to a specified
|
15 | 15 | * target type.
|
16 | 16 | */
|
17 |
| -interface StringToObjectConverter { |
| 17 | +abstract class StringToObjectConverter implements Converter { |
| 18 | + |
| 19 | + @Override |
| 20 | + public final boolean canConvert(Object source, TypeDescriptor targetType) { |
| 21 | + return canConvert(targetType.getType()); |
| 22 | + } |
18 | 23 |
|
19 | 24 | /**
|
20 | 25 | * Determine if this converter can convert from a {@link String} to the
|
21 | 26 | * supplied target type (which is guaranteed to be a wrapper type for
|
22 | 27 | * primitives — for example, {@link Integer} instead of {@code int}).
|
23 | 28 | */
|
24 |
| - boolean canConvertTo(Class<?> targetType); |
| 29 | + abstract boolean canConvert(Class<?> targetType); |
25 | 30 |
|
26 |
| - /** |
27 |
| - * Convert the supplied {@link String} to the supplied target type (which is |
28 |
| - * guaranteed to be a wrapper type for primitives — for example, |
29 |
| - * {@link Integer} instead of {@code int}). |
30 |
| - * |
31 |
| - * <p>This method will only be invoked in {@link #canConvertTo(Class)} |
32 |
| - * returned {@code true} for the same target type. |
33 |
| - */ |
34 |
| - Object convert(String source, Class<?> targetType) throws Exception; |
| 31 | + @Override |
| 32 | + public final Object convert(Object source, TypeDescriptor targetType, ClassLoader classLoader) { |
| 33 | + return convert((String) source, targetType.getType(), classLoader); |
| 34 | + } |
35 | 35 |
|
36 | 36 | /**
|
37 | 37 | * Convert the supplied {@link String} to the supplied target type (which is
|
38 | 38 | * guaranteed to be a wrapper type for primitives — for example,
|
39 | 39 | * {@link Integer} instead of {@code int}).
|
40 | 40 | *
|
41 |
| - * <p>This method will only be invoked in {@link #canConvertTo(Class)} |
| 41 | + * <p>This method will only be invoked if {@link #canConvert(Class)} |
42 | 42 | * returned {@code true} for the same target type.
|
43 |
| - * |
44 |
| - * <p>The default implementation simply delegates to {@link #convert(String, Class)}. |
45 |
| - * Can be overridden by concrete implementations of this interface that need |
46 |
| - * access to the supplied {@link ClassLoader}. |
47 | 43 | */
|
48 |
| - default Object convert(String source, Class<?> targetType, ClassLoader classLoader) throws Exception { |
49 |
| - return convert(source, targetType); |
50 |
| - } |
| 44 | + abstract Object convert(String source, Class<?> targetType, ClassLoader classLoader); |
51 | 45 |
|
52 | 46 | }
|
0 commit comments