Grails domain class response as json (Grails)

With a grails Controller you can response your Domain class objects as json response.
it is as easy as follows:

Let's create a Product domain class as example

  Then run grails generate-all com.ocorp.grails.Product

 This will generate all our controllers, views, test cases.

 Inside our ProductController let's create a list() method or name it as you like better, and reneder the contest as json as follows:

When you go to /yourAppContext/product/list the response will be json for all the elements for your Domian Class Product:


This can be found at grails documentation http://grails.github.io/grails-doc/2.3.4/guide/theWebLayer.html#xmlAndJSON


Comments