Parsing and binding date formats from params in Grails.

"Grails is a powerful web framework for the Java platform aimed at multiplying developers' productivity" - grails.

We recently decided to rewrite some parts of our software ( written in grails )as web applications. 

The reason we made that decision is something I hope to write about soon. The task required us to send JSON strings (POST request) that contain datetime information along with other bits for data to the server. 

To bind a date string from the 'param' seamlessly ( without writing extra code to extract the date in your controller) you need to add the following to your grails config file ( config.groovy or application.yml ).

grails.databinding.dateFormats = [ "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "yyyy-MM-dd'T'HH:mm:ss.SSSZ" ,'yyyy-MM-dd HH:mm:ss.S','MMddyyyy' ]

With the above configuration in place, there was no need to extract the date and bind it manually to the domain class or command object. 


Popular posts from this blog

How to accept PayPal payments on Grails

How to enable Grails application to send SMS via Twilio API

How to upgrade Grails 2 applications and plugins to Grails 3