alignment with backported 3.0.6 code (SPR-8538)
This commit is contained in:
parent
718f025d64
commit
0df4631788
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -49,7 +49,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
|
||||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), conversionService);
|
||||
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), this.conversionService);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -64,7 +64,8 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
|
|||
Object sourceElement = Array.get(source, i);
|
||||
target.add(sourceElement);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
Object sourceElement = Array.get(source, i);
|
||||
Object targetElement = this.conversionService.convert(sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -43,7 +43,7 @@ final class ArrayToObjectConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
|
||||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, conversionService);
|
||||
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, this.conversionService);
|
||||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -49,7 +49,7 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
|
||||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), conversionService);
|
||||
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), this.conversionService);
|
||||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
|
|
@ -66,4 +66,4 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
|
|||
return array;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -63,7 +63,8 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert
|
|||
for (Object element : sourceCollection) {
|
||||
target.add(element);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
for (Object sourceElement : sourceCollection) {
|
||||
Object targetElement = this.conversionService.convert(sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());
|
||||
target.add(targetElement);
|
||||
|
|
@ -72,4 +73,4 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert
|
|||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ final class CollectionToObjectConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
|
||||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, conversionService);
|
||||
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, this.conversionService);
|
||||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -45,7 +45,7 @@ final class CollectionToStringConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
|
||||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, conversionService);
|
||||
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, this.conversionService);
|
||||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
|
|
@ -69,4 +69,4 @@ final class CollectionToStringConverter implements ConditionalGenericConverter {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -41,7 +41,7 @@ abstract class ConversionUtils {
|
|||
throw new ConversionFailedException(sourceType, targetType, source, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean canConvertElements(TypeDescriptor sourceElementType, TypeDescriptor targetElementType, ConversionService conversionService) {
|
||||
if (targetElementType == null) {
|
||||
// yes
|
||||
|
|
@ -51,19 +51,18 @@ abstract class ConversionUtils {
|
|||
// maybe
|
||||
return true;
|
||||
}
|
||||
boolean canConvert = conversionService.canConvert(sourceElementType, targetElementType);
|
||||
if (canConvert) {
|
||||
if (conversionService.canConvert(sourceElementType, targetElementType)) {
|
||||
// yes
|
||||
return true;
|
||||
} else {
|
||||
if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) {
|
||||
// maybe;
|
||||
return true;
|
||||
} else {
|
||||
// no;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) {
|
||||
// maybe;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// no;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -72,11 +72,11 @@ final class MapToMapConverter implements ConditionalGenericConverter {
|
|||
// internal helpers
|
||||
|
||||
private boolean canConvertKey(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return ConversionUtils.canConvertElements(sourceType.getMapKeyTypeDescriptor(), targetType.getMapKeyTypeDescriptor(), conversionService);
|
||||
return ConversionUtils.canConvertElements(sourceType.getMapKeyTypeDescriptor(), targetType.getMapKeyTypeDescriptor(), this.conversionService);
|
||||
}
|
||||
|
||||
private boolean canConvertValue(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return ConversionUtils.canConvertElements(sourceType.getMapValueTypeDescriptor(), targetType.getMapValueTypeDescriptor(), conversionService);
|
||||
return ConversionUtils.canConvertElements(sourceType.getMapValueTypeDescriptor(), targetType.getMapValueTypeDescriptor(), this.conversionService);
|
||||
}
|
||||
|
||||
private Object convertKey(Object sourceKey, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
|
|
@ -93,4 +93,4 @@ final class MapToMapConverter implements ConditionalGenericConverter {
|
|||
return this.conversionService.convert(sourceValue, sourceType.mapValueTypeDescriptor(sourceValue), targetType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -44,7 +44,7 @@ final class ObjectToArrayConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
|
||||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(), conversionService);
|
||||
return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(), this.conversionService);
|
||||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
|
|
@ -57,4 +57,4 @@ final class ObjectToArrayConverter implements ConditionalGenericConverter {
|
|||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -46,7 +46,7 @@ final class ObjectToCollectionConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
|
||||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(), conversionService);
|
||||
return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(), this.conversionService);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -56,12 +56,13 @@ final class ObjectToCollectionConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), 1);
|
||||
if (targetType.getElementTypeDescriptor() == null || targetType.getElementTypeDescriptor().isCollection()) {
|
||||
target.add(source);
|
||||
} else {
|
||||
target.add(source);
|
||||
}
|
||||
else {
|
||||
Object singleElement = this.conversionService.convert(source, sourceType, targetType.getElementTypeDescriptor());
|
||||
target.add(singleElement);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -48,7 +48,7 @@ final class StringToBooleanConverter implements Converter<String, Boolean> {
|
|||
|
||||
public Boolean convert(String source) {
|
||||
String value = source.trim();
|
||||
if (value.length() == 0) {
|
||||
if ("".equals(value)) {
|
||||
return null;
|
||||
}
|
||||
value = value.toLowerCase();
|
||||
|
|
|
|||
Loading…
Reference in New Issue