Custom string formatting in Grails JSON marshaller

Posted by ethaler on Stack Overflow See other posts from Stack Overflow or by ethaler
Published on 2011-11-17T22:26:22Z Indexed on 2011/11/18 17:50 UTC
Read the original article Hit count: 437

Filed under:
|
|
|
|

I am looking for a way to do some string formatting through Grails JSON conversion, similar to custom formatting dates, which I found in this post.

Something like this:

import grails.converters.JSON;

class BootStrap {

     def init = { servletContext ->
         JSON.registerObjectMarshaller(String) {
            return it?.trim()             }
     }
     def destroy = {
     }
}

I know custom formatting can be done on a per domain class basis, but I am looking for a more global solution.

© Stack Overflow or respective owner

Related posts about JSON

Related posts about grails