I am testing out a controller and simply want to retrieve the JSON. However, I’m noticing that the controller returns data but it does not return the JSON properly with the key/value pairs. It literally only returns the data. I notice however, that if I use Incident.getAll(), it returns the JSON properly. For example, it will return [INCIDENTID: “Value”] as opposed to using executreQuery which just returns the data.
My code:
def incident = Incident.executeQuery("select a.INCIDENTID from Incident a")
render incident as JSON
The result from
executeQueryis a list of the properties you specified, not actual domain objects. For example:If you want domain objects, you can use
findAllinstead. Try something like this: