1

I have implemented domain class:

package xxx

class Machine {

    String name

    static constraints = {
    }
}

and I also have got a service:

package xxx

import javax.ws.rs.Path
import javax.ws.rs.GET
import javax.ws.rs.Produces
import grails.converters.JSON
import org.json.simple.JSONObject


@Path('/api/machine')
class MachineService {

    @GET
    @Produces(['application/json'])
    def String readAll() {
        Machine.findAll() as JSON
    }
}

and the output is:

[{"class":"xxx.Machine","id":1,"name":"test1"},{"class":"xxx.Machine","id":2,"name":"test2"},{"class":"xxx.Machine","id":3,"name":"test3"}]

I would like to remove field "class". Could you show me the easiest way to reach this goal ?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ruhungry
  • 4,506
  • 20
  • 54
  • 98

1 Answers1

2

See my answer here. Just register custom marshaller and remove class property from all rendered classes

Update: Change excluded properties like this: String[] excludedProperties=['metaClass','class']

Community
  • 1
  • 1
Mr. Cat
  • 3,522
  • 2
  • 17
  • 26
  • how can I remove class property ? – ruhungry May 31 '13 at 15:12
  • Have you read the answer? The full description is here. Change excluded properties like this: String[] excludedProperties=['metaClass','class'] and thats it. – Mr. Cat May 31 '13 at 15:27
  • Eh, sorry...I had been trying plenty solutions before I tried this one. After quick nap I read your post again and of course, it works :) – ruhungry Jun 01 '13 at 11:51