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.
Try to create custom marshaller that use specific formatting for property names or class. Just look at the marshaller bellow and modify it:
}
The register in bootstrap:
In my example I just scip 'metaClass' and 'class' fields. I think the most common way