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

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3761 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2010-10-14 19:44:26 +00:00
parent a52450e21a
commit 5d4b7ee227
2 changed files with 7 additions and 5 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -55,8 +55,9 @@ final class StringToArrayConverter implements ConditionalGenericConverter {
String[] fields = StringUtils.commaDelimitedListToStringArray(string); String[] fields = StringUtils.commaDelimitedListToStringArray(string);
Object target = Array.newInstance(targetType.getElementType(), fields.length); Object target = Array.newInstance(targetType.getElementType(), fields.length);
for (int i = 0; i < fields.length; i++) { for (int i = 0; i < fields.length; i++) {
Object sourceElement = fields[i]; String sourceElement = fields[i];
Object targetElement = this.conversionService.convert(sourceElement, sourceType, targetType.getElementTypeDescriptor()); Object targetElement = this.conversionService.convert(sourceElement.trim(),
sourceType, targetType.getElementTypeDescriptor());
Array.set(target, i, targetElement); Array.set(target, i, targetElement);
} }
return target; return target;

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -57,7 +57,8 @@ final class StringToCollectionConverter implements ConditionalGenericConverter {
String[] fields = StringUtils.commaDelimitedListToStringArray(string); String[] fields = StringUtils.commaDelimitedListToStringArray(string);
Collection target = CollectionFactory.createCollection(targetType.getType(), fields.length); Collection target = CollectionFactory.createCollection(targetType.getType(), fields.length);
for (String sourceElement : fields) { 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); target.add(targetElement);
} }
return target; return target;