I just struggled with this exact issue this week. I wanted to send the domain class as JSON, but at the same time add the errorMessage property, which could potentially contain additional information.
It turns out that when used as JSON in grails, it sends back the converter object, but it can be turned into a jconObject instance using JSON.parse () which we can easily add to the new values.
def jsonObject = JSON.parse((entity AS JSON).toString()) jsonObject.put("success", "yes") render jsonObject as JSON
I think there are several different approaches, but this turned out to be the easiest for me, since I already have custom converters for most of my domain classes, and I did not want to add any other transient properties to my domain object.
source share