I’ve a method in my Grails controller that should return a JSON, a property of the JSON is a Date object, but when I do:
render myObject as JSON
the output is like:
{
"dateProperty": "2010-12-31T23:00:00Z",
"otherProperty" : "aValue..."
}
Is there a way to change the default date format used from the converter?
I’ve tried to set the property grails.converters.json.date and also grails.date.formats in the Config.groovy, but this doesn’t work.
Am I doing something wrong or is there another way to do it?
Thanks
I generally use a custom Marshaller. Assume you have the following Domain
Create a class under src/groovy like this
Then in your Bootstrap file do the following:
The reason I do it as an array like that is because I have multiple marshallers.
Now, anytime you do
address as JSON, you’ll get the JSON you’ve described and you’re correct date format. I know this seems like overkill for formatting a date in JSON but this has a lot of other benefits.