krasserm / grails-jaxrs

JAX-RS Plugin for Grails
http://code.google.com/p/grails-jaxrs/
Apache License 2.0
50 stars 48 forks source link

Renderer makes date property null before db operation #64

Closed daptordarattler closed 8 years ago

daptordarattler commented 9 years ago

I have a date property on a domain model

Consignment{
       String  description
       Date dateDone

       Date dateCreated
       Date lastUpdated
}

Any time I update the dateDone from the client with javascript using code

consignment.dateDone = new Date().toISOString()

it is nulled in the resource code before even getting to the service operations I have no Idea why. Its got me pulling out my hair all day.

noamt commented 9 years ago

If you've got trouble debugging it, please post an example project or create a pull request with a test that reproduces it.

budjb commented 8 years ago

This issue was moved to budjb/grails-jaxrs#23

daptordarattler commented 8 years ago

I had the same problem for a long time and only recently solved it. The grails data binding for date formats does not bind with the javascript multiple date formats well so you have to add some date format patterns in Config.groovy to fix this.

Here is the code I used:

//compatible with dates expressed as "2014-01-28T12:56:37+0100" as a wider range of date patterns
grails.databinding.dateFormats = ['yyyy-MM-dd HH:mm:ss.S',"yyyy-MM-dd HH:mm:ss.S z",
                          'yyyy-MM-dd HH:mm:ss.SSS',"yyyy-MM-dd HH:mm:ss.SSS z", 
                           "yyyy-MM-dd HH:mm:ss.SSS'Z'","yyyy-MM-ddHH:mm:ss.s'Z'","yyyy-MM-dd'T'HH:mm:ss'Z'",
                           "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'","yyyy-MM-dd'T'HH:mm:ss.S'Z'",
                           "EEE MMM dd yyyy HH:mm:ss 'GMT'Z (z)"]