I'm working with a JSON file, and I need to transform it into an object. Everything seems easy so far, but I found a problem trying to parse dates.
I'm trying to do something like this:
//My JSON file
data={
"title":"myTitle"
"releaseDate":"2012-05-28"
}
//Myclass
class Book{
String title
Date date
}
Book book = JSON.parse(data)
And I receive an error:
Cannot cast object with class 'org.codehaus.groovy.grails.web.json.JSONObject' to class 'Book' due to:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '2012-05-28' with class 'java.lang.String' to class 'java.util.Date'
I think I know why is this happening (Obviously, I can't cast a String into a Date) but I've no idea how to fix it.
I've also tried to define in Config.groovy
my format date, like this:
grails.converters.json.date = 'yyyy-MM-dd'