Grails json string converter with Dates
I'm POSTing json data to a Grails controller which I then parse using JSON.parse. It all works fine except for date fields. I don't believe there is an explicit syntax in json to represen开发者_开发百科t a Date but I've tried a number of formats with no luck. Can anyone tell me what format I should use so that the grails JSON parser can create a Date object.
There isn't a specific format, but you can define your own. For example, these guys here are adding a '@' to the beginning and the end of the string.
According to Grails docs here, you can define:
grails.converters.json.date (String) - Configure how Date values are serialized to JSON
- "default" - String representation according to the JSON specification
- "javascript" - new Date(...)
Update: It appears that there is no mapping to Java Date objects. If you know the fields that are dates, you can parse them into Dates
精彩评论