Browse Source

StringToArray/CollectionConverter trims element values before trying to convert them (SPR-7657)

3.0.x
Juergen Hoeller 15 years ago
parent
commit
e1dbb66798
  1. 7
      org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java
  2. 5
      org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java

7
org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.
@ -55,8 +55,9 @@ final class StringToArrayConverter implements ConditionalGenericConverter { @@ -55,8 +55,9 @@ final class StringToArrayConverter implements ConditionalGenericConverter {
String[] fields = StringUtils.commaDelimitedListToStringArray(string);
Object target = Array.newInstance(targetType.getElementType(), fields.length);
for (int i = 0; i < fields.length; i++) {
Object sourceElement = fields[i];
Object targetElement = this.conversionService.convert(sourceElement, sourceType, targetType.getElementTypeDescriptor());
String sourceElement = fields[i];
Object targetElement = this.conversionService.convert(sourceElement.trim(),
sourceType, targetType.getElementTypeDescriptor());
Array.set(target, i, targetElement);
}
return target;

5
org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.
@ -57,7 +57,8 @@ final class StringToCollectionConverter implements ConditionalGenericConverter { @@ -57,7 +57,8 @@ final class StringToCollectionConverter implements ConditionalGenericConverter {
String[] fields = StringUtils.commaDelimitedListToStringArray(string);
Collection target = CollectionFactory.createCollection(targetType.getType(), fields.length);
for (String sourceElement : fields) {
Object targetElement = this.conversionService.convert(sourceElement, sourceType, targetType.getElementTypeDescriptor(sourceElement));
Object targetElement = this.conversionService.convert(sourceElement.trim(),
sourceType, targetType.getElementTypeDescriptor(sourceElement));
target.add(targetElement);
}
return target;

Loading…
Cancel
Save