bean properties of type enum array/collection can be populated with comma-separated String (SPR-6547)

This commit is contained in:
Juergen Hoeller
2009-12-13 13:21:30 +00:00
parent b497f6ccad
commit 5f9b444319
3 changed files with 89 additions and 4 deletions

View File

@@ -202,6 +202,13 @@ class TypeConverterDelegate {
// Value not of required type?
if (editor != null || (requiredType != null && !ClassUtils.isAssignableValue(requiredType, convertedValue))) {
if (requiredType != null && Collection.class.isAssignableFrom(requiredType) &&
convertedValue instanceof String && typeDescriptor.getMethodParameter() != null) {
Class elementType = GenericCollectionTypeResolver.getCollectionParameterType(typeDescriptor.getMethodParameter());
if (elementType != null && Enum.class.isAssignableFrom(elementType)) {
convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue);
}
}
if (editor == null) {
editor = findDefaultEditor(requiredType, typeDescriptor);
}
@@ -214,6 +221,9 @@ class TypeConverterDelegate {
if (convertedValue != null) {
if (requiredType.isArray()) {
// Array required -> apply appropriate conversion of elements.
if (convertedValue instanceof String && Enum.class.isAssignableFrom(requiredType.getComponentType())) {
convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue);
}
return (T) convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType());
}
else if (convertedValue instanceof Collection) {