From 5d4b7ee22716f2d5d717c6a61b6569c9f993074e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 14 Oct 2010 19:44:26 +0000 Subject: [PATCH] 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 --- .../core/convert/support/StringToArrayConverter.java | 7 ++++--- .../core/convert/support/StringToCollectionConverter.java | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java index 53a648ea8c2..d9f40cb419b 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java @@ -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 { 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; diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java index c501c46369c..744caa0b6e8 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java @@ -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 { 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;