Pergunta

Consider a simple class as :-

class Person{
     String name
     String email
     int age
     String mobileNum
}

I want to selectively send 'id' & 'email' attributes as JSON response. When using:-

return theObject as JSON

the response has all attribute:value pair.

Foi útil?

Solução

You can register your own JSON marshaller (at BootStrap.groovy, for example), like:

JSON.registerObjectMarshaller(Person) { Person it ->
  return [
    id    : it.id, 
    email : it.email 
  ]
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top