Is there a way to remove the class field in a JSON converter?
Example:
import testproject.*
import grails.converters.*
emp = new Employee()
emp
def a = Employee.list()
String[] excludedProperties=['class', 'metaClass']
render(contentType: "text/json") {
employees = array {
a.each {
employee it.properties.findAll { k,v -> !(k in excludedProperties) }
}
}
}
This works for me. You can easily pass in any property to exclude. Or turn it around:
def a = Employee.list()
String[] includedProperties=['id', 'lastName']
render(contentType: "text/json") {
employees = array {
a.each {
employee it.properties.findAll { k,v -> (k in includedProperties) }
}
}
}
Beware: This is only for simple objects. If you see "Misplaced key: expected mode of KEY but was OBJECT" this solution is not for you. :)
HP