I checked your code: this is unbelievable, but I cannot reproduce your problem. I downloaded the latest version of spring (3.0.5), this is my controller:
package test; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/test/**") public class MyController { private static final Logger logger = Logger.getLogger(MyController.class); @RequestMapping(value = "/test/params", method = RequestMethod.GET) public void test(SearchRequestParams requestParams, BindingResult result) { logger.debug("fq = " + StringUtils.join(requestParams.getFq(), "|")); } }
this is my SearchRequestParams class:
package test; public class SearchRequestParams { private String[] fq; public String[] getFq() { return fq; } public void setFq(String[] fq) { this.fq = fq; } }
and this is my simple spring configuration:
<bean id="urlMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> <bean class="test.MyController" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/jsp/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean>
I tested my code in tomcat 7.0.8; when I type http://localhost:8080/testweb/test/params.htm?fq=foo,bar , I can read this line in my log file: DEBUG fq = foo,bar . What are the differences from my code? Am I doing something wrong? I would like to help you, so if you have any doubts or I can do some other tests for you, it will be nice.
UPDATE / DECISION
With your code, I reproduced the problem; you have the <mvc:annotation-driven /> in the dispatcher servlet configuration, so you quietly use the default conversion service, an instance of FormattingConversionService , which contains the default converter from String to String[] , which uses a comma as a separator. You must use another bean conversion service containing your own converter from String to String[] . You must use a different delimiter, I chose to use ";" because this is the separator commonly used in the query string ("? first = 1; second = 2; third = 3"):
import org.springframework.core.convert.converter.Converter; import org.springframework.util.StringUtils; public class CustomStringToArrayConverter implements Converter<String, String[]>{ @Override public String[] convert(String source) { return StringUtils.delimitedListToStringArray(source, ";"); } }
Then you must specify this bean conversion service in your configuration:
<mvc:annotation-driven conversion-service="conversionService" /> <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"> <property name="converters"> <list> <bean class="au.org.ala.testspringbinding.CustomStringToArrayConverter" /> </list> </property> </bean>
The problem is fixed, now you should check for any side effects. I hope you donβt need the original conversion from String to String[] (with a comma as a separator) in your application. ;-)