title: Custom string formatting in Grails JSON marshaller
body: <p>I am looking for a way to do some string formatting through Grails JSON conversion, similar to custom formatting dates, which I found in <a href="https://stackoverflow.com/questions/690370/how-to-return-specific-date-format-as-json-in-grails">this post</a>.</p>
  
  <p>Something like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>import grails.converters.JSON;
  
  class BootStrap {
  
       def init = { servletContext -&gt;
           JSON.registerObjectMarshaller(String) {
              return it?.trim()             }
       }
       def destroy = {
       }
  }
  </code></pre>
  
  <p>I know custom formatting can be done on a per domain class basis, but I am looking for a more global solution.</p>