Polish whitespace for conversion service packages
This commit is contained in:
@@ -35,7 +35,7 @@ abstract class AbstractDescriptor {
|
||||
Assert.notNull(type, "Type must not be null");
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Class<?> getType() {
|
||||
return this.type;
|
||||
@@ -48,13 +48,13 @@ abstract class AbstractDescriptor {
|
||||
}
|
||||
else if (isArray()) {
|
||||
Class<?> elementType = getType().getComponentType();
|
||||
return new TypeDescriptor(nested(elementType, 0));
|
||||
return new TypeDescriptor(nested(elementType, 0));
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TypeDescriptor getMapKeyTypeDescriptor() {
|
||||
if (isMap()) {
|
||||
Class<?> keyType = resolveMapKeyType();
|
||||
@@ -64,7 +64,7 @@ abstract class AbstractDescriptor {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TypeDescriptor getMapValueTypeDescriptor() {
|
||||
if (isMap()) {
|
||||
Class<?> valueType = resolveMapValueType();
|
||||
@@ -96,33 +96,33 @@ abstract class AbstractDescriptor {
|
||||
throw new IllegalStateException("Not a collection, array, or map: cannot resolve nested value types");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// subclassing hooks
|
||||
|
||||
|
||||
public abstract Annotation[] getAnnotations();
|
||||
|
||||
protected abstract Class<?> resolveCollectionElementType();
|
||||
|
||||
|
||||
protected abstract Class<?> resolveMapKeyType();
|
||||
|
||||
|
||||
protected abstract Class<?> resolveMapValueType();
|
||||
|
||||
|
||||
protected abstract AbstractDescriptor nested(Class<?> type, int typeIndex);
|
||||
|
||||
|
||||
|
||||
// internal helpers
|
||||
|
||||
|
||||
private boolean isCollection() {
|
||||
return Collection.class.isAssignableFrom(getType());
|
||||
}
|
||||
|
||||
|
||||
private boolean isArray() {
|
||||
return getType().isArray();
|
||||
}
|
||||
|
||||
|
||||
private boolean isMap() {
|
||||
return Map.class.isAssignableFrom(getType());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ class BeanPropertyDescriptor extends AbstractDescriptor {
|
||||
private final Property property;
|
||||
|
||||
private final MethodParameter methodParameter;
|
||||
|
||||
|
||||
private final Annotation[] annotations;
|
||||
|
||||
|
||||
|
||||
public BeanPropertyDescriptor(Property property) {
|
||||
super(property.getType());
|
||||
@@ -45,7 +45,7 @@ class BeanPropertyDescriptor extends AbstractDescriptor {
|
||||
public Annotation[] getAnnotations() {
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?> resolveCollectionElementType() {
|
||||
return GenericCollectionTypeResolver.getCollectionParameterType(this.methodParameter);
|
||||
@@ -65,10 +65,10 @@ class BeanPropertyDescriptor extends AbstractDescriptor {
|
||||
protected AbstractDescriptor nested(Class<?> type, int typeIndex) {
|
||||
MethodParameter methodParameter = new MethodParameter(this.methodParameter);
|
||||
methodParameter.increaseNestingLevel();
|
||||
methodParameter.setTypeIndexForCurrentLevel(typeIndex);
|
||||
methodParameter.setTypeIndexForCurrentLevel(typeIndex);
|
||||
return new BeanPropertyDescriptor(type, this.property, methodParameter, this.annotations);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// internal
|
||||
|
||||
@@ -78,5 +78,5 @@ class BeanPropertyDescriptor extends AbstractDescriptor {
|
||||
this.methodParameter = methodParameter;
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -52,5 +52,5 @@ class ClassDescriptor extends AbstractDescriptor {
|
||||
protected AbstractDescriptor nested(Class<?> type, int typeIndex) {
|
||||
return new ClassDescriptor(type);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.core.NestedRuntimeException;
|
||||
* Base class for exceptions thrown by the conversion system.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @since 3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class ConversionException extends NestedRuntimeException {
|
||||
|
||||
@@ -63,7 +63,7 @@ public interface ConversionService {
|
||||
* @throws IllegalArgumentException if targetType is null
|
||||
*/
|
||||
<T> T convert(Object source, Class<T> targetType);
|
||||
|
||||
|
||||
/**
|
||||
* Convert the source to targetType.
|
||||
* The TypeDescriptors provide additional context about the source and target locations where conversion will occur, often object fields or property locations.
|
||||
@@ -77,4 +77,4 @@ public interface ConversionService {
|
||||
*/
|
||||
Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class FieldDescriptor extends AbstractDescriptor {
|
||||
public Annotation[] getAnnotations() {
|
||||
return TypeDescriptor.nullSafeAnnotations(this.field.getAnnotations());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?> resolveCollectionElementType() {
|
||||
return GenericCollectionTypeResolver.getCollectionFieldType(this.field, this.nestingLevel, this.typeIndexesPerLevel);
|
||||
|
||||
@@ -34,7 +34,7 @@ class ParameterDescriptor extends AbstractDescriptor {
|
||||
super(methodParameter.getParameterType());
|
||||
if (methodParameter.getNestingLevel() != 1) {
|
||||
throw new IllegalArgumentException("MethodParameter argument must have its nestingLevel set to 1");
|
||||
}
|
||||
}
|
||||
this.methodParameter = methodParameter;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class ParameterDescriptor extends AbstractDescriptor {
|
||||
return TypeDescriptor.nullSafeAnnotations(this.methodParameter.getParameterAnnotations());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?> resolveCollectionElementType() {
|
||||
return GenericCollectionTypeResolver.getCollectionParameterType(this.methodParameter);
|
||||
|
||||
@@ -50,7 +50,7 @@ public final class Property {
|
||||
private final Method writeMethod;
|
||||
|
||||
private final String name;
|
||||
|
||||
|
||||
private final MethodParameter methodParameter;
|
||||
|
||||
private final Annotation[] annotations;
|
||||
@@ -112,7 +112,7 @@ public final class Property {
|
||||
|
||||
|
||||
// package private
|
||||
|
||||
|
||||
MethodParameter getMethodParameter() {
|
||||
return this.methodParameter;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public final class Property {
|
||||
|
||||
|
||||
// internal helpers
|
||||
|
||||
|
||||
private String resolveName() {
|
||||
if (this.readMethod != null) {
|
||||
int index = this.readMethod.getName().indexOf("get");
|
||||
@@ -166,27 +166,27 @@ public final class Property {
|
||||
}
|
||||
return write;
|
||||
}
|
||||
|
||||
|
||||
private MethodParameter resolveReadMethodParameter() {
|
||||
if (getReadMethod() == null) {
|
||||
return null;
|
||||
}
|
||||
return resolveParameterType(new MethodParameter(getReadMethod(), -1));
|
||||
return resolveParameterType(new MethodParameter(getReadMethod(), -1));
|
||||
}
|
||||
|
||||
private MethodParameter resolveWriteMethodParameter() {
|
||||
if (getWriteMethod() == null) {
|
||||
return null;
|
||||
}
|
||||
return resolveParameterType(new MethodParameter(getWriteMethod(), 0));
|
||||
return resolveParameterType(new MethodParameter(getWriteMethod(), 0));
|
||||
}
|
||||
|
||||
private MethodParameter resolveParameterType(MethodParameter parameter) {
|
||||
// needed to resolve generic property types that parameterized by sub-classes e.g. T getFoo();
|
||||
GenericTypeResolver.resolveParameterType(parameter, getObjectType());
|
||||
return parameter;
|
||||
return parameter;
|
||||
}
|
||||
|
||||
|
||||
private Annotation[] resolveAnnotations() {
|
||||
Map<Class<?>, Annotation> annMap = new LinkedHashMap<Class<?>, Annotation>();
|
||||
Method readMethod = getReadMethod();
|
||||
@@ -238,4 +238,4 @@ public final class Property {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,5 +47,5 @@ public interface ConditionalGenericConverter extends GenericConverter {
|
||||
* @return true if conversion should be performed, false otherwise
|
||||
*/
|
||||
boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ package org.springframework.core.convert.converter;
|
||||
* Implementations of this interface are thread-safe and can be shared.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @param <S> The source type
|
||||
* @param <T> The target type
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface Converter<S, T> {
|
||||
|
||||
@@ -20,7 +20,7 @@ package org.springframework.core.convert.converter;
|
||||
* A factory for "ranged" converters that can convert objects from S to subtypes of R.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @since 3.0
|
||||
* @param <S> The source type converters created by this factory can convert from
|
||||
* @param <R> The target range (or base) type converters created by this factory can convert to;
|
||||
* for example {@link Number} for a set of number subtypes.
|
||||
|
||||
@@ -24,7 +24,7 @@ package org.springframework.core.convert.converter;
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface ConverterRegistry {
|
||||
|
||||
|
||||
/**
|
||||
* Add a plain converter to this registry.
|
||||
* The convertible sourceType/targetType pair is derived from the Converter's parameterized types.
|
||||
@@ -44,11 +44,11 @@ public interface ConverterRegistry {
|
||||
* Add a generic converter to this registry.
|
||||
*/
|
||||
void addConverter(GenericConverter converter);
|
||||
|
||||
|
||||
/**
|
||||
* Add a ranged converter factory to this registry.
|
||||
* The convertible sourceType/rangeType pair is derived from the ConverterFactory's parameterized types.
|
||||
* @throws IllegalArgumentException if the parameterized types could not be resolved.
|
||||
* @throws IllegalArgumentException if the parameterized types could not be resolved.
|
||||
*/
|
||||
void addConverterFactory(ConverterFactory<?, ?> converterFactory);
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Converts an Array to another Array.
|
||||
* First adapts the source array to a List, then delegates to {@link CollectionToArrayConverter} to perform the target array conversion.
|
||||
*
|
||||
* First adapts the source array to a List, then delegates to {@link CollectionToArrayConverter} to perform the target array conversion.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -48,7 +48,7 @@ final class ArrayToArrayConverter implements ConditionalGenericConverter {
|
||||
return this.helperConverter.matches(sourceType, targetType);
|
||||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
||||
* <p>First, creates a new Collection of the requested targetType.
|
||||
* Then adds each array element to the target collection.
|
||||
* Will perform an element conversion from the source component type to the collection's parameterized type if necessary.
|
||||
*
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -57,7 +57,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
int length = Array.getLength(source);
|
||||
Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), length);
|
||||
if (targetType.getElementTypeDescriptor() == null) {
|
||||
@@ -73,7 +73,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
|
||||
sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());
|
||||
target.add(targetElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
||||
|
||||
/**
|
||||
* Converts an Array to an Object by returning the first array element after converting it to the desired targetType.
|
||||
*
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.ObjectUtils;
|
||||
/**
|
||||
* Converts an Array to a comma-delimited String.
|
||||
* This implementation first adapts the source Array to a List, then delegates to {@link CollectionToStringConverter} to perform the target String conversion.
|
||||
*
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.util.NumberUtils;
|
||||
* @see java.lang.Float
|
||||
* @see java.lang.Double
|
||||
* @see java.math.BigDecimal
|
||||
* @see NumberUtils
|
||||
* @see NumberUtils
|
||||
*/
|
||||
final class CharacterToNumberFactory implements ConverterFactory<Character, Number> {
|
||||
|
||||
@@ -47,11 +47,11 @@ final class CharacterToNumberFactory implements ConverterFactory<Character, Numb
|
||||
private static final class CharacterToNumber<T extends Number> implements Converter<Character, T> {
|
||||
|
||||
private final Class<T> targetType;
|
||||
|
||||
|
||||
public CharacterToNumber(Class<T> targetType) {
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
|
||||
public T convert(Character source) {
|
||||
return NumberUtils.convertNumberToTargetClass((short) source.charValue(), this.targetType);
|
||||
}
|
||||
|
||||
@@ -61,4 +61,4 @@ final class CollectionToObjectConverter implements ConditionalGenericConverter {
|
||||
return this.conversionService.convert(firstElement, sourceType.elementTypeDescriptor(firstElement), targetType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,4 +49,4 @@ final class FallbackObjectToStringConverter implements ConditionalGenericConvert
|
||||
return (source != null ? source.toString() : null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
GenericConverter.ConvertiblePair typeInfo = new GenericConverter.ConvertiblePair(sourceType, targetType);
|
||||
addConverter(new ConverterAdapter(typeInfo, converter));
|
||||
}
|
||||
|
||||
|
||||
public void addConverter(GenericConverter converter) {
|
||||
Set<GenericConverter.ConvertiblePair> convertibleTypes = converter.getConvertibleTypes();
|
||||
for (GenericConverter.ConvertiblePair convertibleType : convertibleTypes) {
|
||||
@@ -119,7 +119,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
}
|
||||
addConverter(new ConverterFactoryAdapter(typeInfo, converterFactory));
|
||||
}
|
||||
|
||||
|
||||
public void removeConvertible(Class<?> sourceType, Class<?> targetType) {
|
||||
getSourceConverterMap(sourceType).remove(targetType);
|
||||
invalidateCache();
|
||||
@@ -131,7 +131,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
|
||||
if (targetType == null) {
|
||||
throw new IllegalArgumentException("The targetType to convert to cannot be null");
|
||||
}
|
||||
}
|
||||
return canConvert(sourceType != null ? TypeDescriptor.valueOf(sourceType) : null, TypeDescriptor.valueOf(targetType));
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
public <T> T convert(Object source, Class<T> targetType) {
|
||||
if (targetType == null) {
|
||||
throw new IllegalArgumentException("The targetType to convert to cannot be null");
|
||||
}
|
||||
}
|
||||
return (T) convert(source, TypeDescriptor.forObject(source), TypeDescriptor.valueOf(targetType));
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
return handleResult(sourceType, targetType, result);
|
||||
}
|
||||
else {
|
||||
return handleConverterNotFound(source, sourceType, targetType);
|
||||
return handleConverterNotFound(source, sourceType, targetType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
public Object convert(Object source, TypeDescriptor targetType) {
|
||||
return convert(source, TypeDescriptor.forObject(source), targetType);
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
List<String> converterStrings = new ArrayList<String>();
|
||||
for (Map<Class<?>, MatchableConverters> targetConverters : this.converters.values()) {
|
||||
@@ -203,7 +203,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
for (String converterString : converterStrings) {
|
||||
builder.append("\t");
|
||||
builder.append(converterString);
|
||||
builder.append("\n");
|
||||
builder.append("\n");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
@@ -243,7 +243,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
else {
|
||||
converter = findConverterForClassPair(sourceType, targetType);
|
||||
if (converter == null) {
|
||||
converter = getDefaultConverter(sourceType, targetType);
|
||||
converter = getDefaultConverter(sourceType, targetType);
|
||||
}
|
||||
if (converter != null) {
|
||||
this.converterCache.put(key, converter);
|
||||
@@ -285,7 +285,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
}
|
||||
return matchable;
|
||||
}
|
||||
|
||||
|
||||
private void invalidateCache() {
|
||||
this.converterCache.clear();
|
||||
}
|
||||
@@ -366,7 +366,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
}
|
||||
}
|
||||
Map<Class<?>, MatchableConverters> objectConverters = getTargetConvertersForSource(Object.class);
|
||||
return getMatchingConverterForTarget(sourceType, targetType, objectConverters);
|
||||
return getMatchingConverterForTarget(sourceType, targetType, objectConverters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,9 +473,9 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
}
|
||||
else {
|
||||
throw new ConverterNotFoundException(sourceType, targetType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Object handleResult(TypeDescriptor sourceType, TypeDescriptor targetType, Object result) {
|
||||
if (result == null) {
|
||||
assertNotPrimitiveTargetType(sourceType, targetType);
|
||||
@@ -486,9 +486,9 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
if (targetType.isPrimitive()) {
|
||||
throw new ConversionFailedException(sourceType, targetType, null,
|
||||
new IllegalArgumentException("A null value cannot be assigned to a primitive type"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private final class ConverterAdapter implements GenericConverter {
|
||||
@@ -516,7 +516,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
}
|
||||
return this.converter.convert(source);
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return this.typeInfo.getSourceType().getName() + " -> " + this.typeInfo.getTargetType().getName() +
|
||||
" : " + this.converter.toString();
|
||||
@@ -613,14 +613,14 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
private static final class ConverterCacheKey {
|
||||
|
||||
private final TypeDescriptor sourceType;
|
||||
|
||||
|
||||
private final TypeDescriptor targetType;
|
||||
|
||||
|
||||
public ConverterCacheKey(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
this.sourceType = sourceType;
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
@@ -631,11 +631,11 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
ConverterCacheKey otherKey = (ConverterCacheKey) other;
|
||||
return this.sourceType.equals(otherKey.sourceType) && this.targetType.equals(otherKey.targetType);
|
||||
}
|
||||
|
||||
|
||||
public int hashCode() {
|
||||
return this.sourceType.hashCode() * 29 + this.targetType.hashCode();
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "ConverterCacheKey [sourceType = " + this.sourceType + ", targetType = " + this.targetType + "]";
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter {
|
||||
private static Method getValueOfMethodOn(Class<?> clazz, Class<?> sourceParameterType) {
|
||||
return ClassUtils.getStaticMethod(clazz, "valueOf", sourceParameterType);
|
||||
}
|
||||
|
||||
|
||||
private static Constructor<?> getConstructor(Class<?> clazz, Class<?> sourceParameterType) {
|
||||
return ClassUtils.getConstructorIfAvailable(clazz, sourceParameterType);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* Converts a comma-delimited String to an Array.
|
||||
* Only matches if String.class can be converted to the target array element type.
|
||||
*
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -47,11 +47,11 @@ final class StringToArrayConverter implements ConditionalGenericConverter {
|
||||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return this.conversionService.canConvert(sourceType, targetType.getElementTypeDescriptor());
|
||||
}
|
||||
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
String string = (String) source;
|
||||
String[] fields = StringUtils.commaDelimitedListToStringArray(string);
|
||||
Object target = Array.newInstance(targetType.getElementTypeDescriptor().getType(), fields.length);
|
||||
@@ -63,4 +63,4 @@ final class StringToArrayConverter implements ConditionalGenericConverter {
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ final class StringToBooleanConverter implements Converter<String, Boolean> {
|
||||
falseValues.add("no");
|
||||
falseValues.add("0");
|
||||
}
|
||||
|
||||
|
||||
public Boolean convert(String source) {
|
||||
String value = source.trim();
|
||||
if ("".equals(value)) {
|
||||
|
||||
@@ -54,7 +54,7 @@ final class StringToCollectionConverter implements ConditionalGenericConverter {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -64,14 +64,14 @@ final class StringToCollectionConverter implements ConditionalGenericConverter {
|
||||
if (targetType.getElementTypeDescriptor() == null) {
|
||||
for (String field : fields) {
|
||||
target.add(field.trim());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (String field : fields) {
|
||||
Object targetElement = this.conversionService.convert(field.trim(), sourceType, targetType.getElementTypeDescriptor());
|
||||
target.add(targetElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.core.convert.converter.Converter;
|
||||
/**
|
||||
* Converts a String to a Properties by calling Properties#load(java.io.InputStream).
|
||||
* Uses ISO-8559-1 encoding required by Properties.
|
||||
*
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user