Recently I started to play with Grails 2.3.4 and discovered a lot of nice features around REST, grails team did really good progress here.

When I was playing I noticed that I always had “class” field in JSON returned to me by grails server when I checked the doc, it was saying that you need to setup JSON renderer like this in resources.groovy file:

import grails.rest.render.json.JsonRenderer

// Place your Spring DSL code here
beans = {
deviceRenderer(JsonRenderer, Device) {
excludes = ['class']
}
}

But when I tried it, it did not work. Well, it did not work for index method, which was returning a collection of devices. You need to define 2 beans: one for collection rendering and another for single object:

import grails.rest.render.json.JsonCollectionRenderer
import grails.rest.render.json.JsonRenderer

// Place your Spring DSL code here
beans = {
deviceCollectionRenderer(JsonCollectionRenderer, Device) {
excludes = ['class']
}

deviceRenderer(JsonRenderer, Device) {
excludes = ['class']
}
}

Now it will work. Same stands for xml, just use XmlCollectionRenderer instead.