title: How to override Grails' default (binding) conversion of parameter values with commas to String array?
body: <p>I'm using Grails 2.3.7 and have a controller method which binds the request to a command class. One of the fields in the command class is a String array, as it expects multiple params with the same name to be specified - e.g. <code>?foo=1&amp;foo=2&amp;foo=3&amp;bar=0</code>.</p>
  
  <p>This works fine most of the time. The one case where it fails is if the param value contains a comma - e.g. <code>?foo=val1,val2&amp;foo=val3,val4</code>. In this case I'm getting an array with 4 values: <code>["val1","val2","val3","val4"]</code>, not the intended output of <code>["val1,val2","val1,val2"]</code>. URL escaping/encoding the comma does not help and in my cases the param value is surrounded by quote characters as well (<code>foo=%22a+string+with+commas,+etc%22</code>).</p>
  
  <p>I had a similar problem with Spring 3.x which I was able to solve: <a href="https://stackoverflow.com/questions/4998748">How to prevent parameter binding from interpreting commas in Spring 3.0.5?</a>. I've attempted one of the answers by adding the following method to my controller:</p>
  
  <pre><code>@InitBinder
  public void initBinder(WebDataBinder binder) {
      binder.registerCustomEditor(String[].class, new StringArrayPropertyEditor(null));
  }
  </code></pre>
  
  <p>However this didn't work. </p>
  
  <p>I also tried specifying a custom conversion service, based on the comment in <a href="https://jira.grails.org/browse/GRAILS-8997" rel="nofollow noreferrer">https://jira.grails.org/browse/GRAILS-8997</a>.</p>
  
  <p>Config/spring/resources.groovy:</p>
  
  <pre><code>beans = {
      conversionService (org.springframework.context.support.ConversionServiceFactoryBean) {
          converters = [new CustomStringToArrayConverter()]
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>import org.springframework.core.convert.converter.Converter
  import org.springframework.util.StringUtils
  
  class CustomStringToArrayConverter implements Converter&lt;String, String[]&gt; {
      @Override
      public String[] convert(String source) {
          return StringUtils.delimitedListToStringArray(source, ";");
      }
  }
  </code></pre>
  
  <p>but I couldn't get this to work either.</p>