0

I'm facing following error while trying unmarshal java.util.Date from JSON in grails controller.

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '2011-10-07 10:24:40' with class 'java.lang.String' to class 'java.util.Date'**

Also, I've tried the following method but still no luck, actually I've doubt wether I've implemented following in right way or not because when i put println statements in following method:

public CustomDateBinder(List formats)

Nothing prints on console.

Grails Date unmarshalling

Community
  • 1
  • 1
mehmood
  • 301
  • 3
  • 19

1 Answers1

0

According to the description of your error message you are trying to convert a String to Date, if you want to do it manually you can use the following method in your Controller (since Grails 2)

 def val = params.date('myDate', 'dd-MM-yyyy') //Obviously you need to change the format

Check the following post for more info: http://mrhaki.blogspot.com/2012/01/grails-goodness-date-request-parameter.html

Ernesto Campohermoso
  • 7,213
  • 1
  • 40
  • 51