Rendering command object in gson

223 views Asked by At

I'm using Grails 3 and org.grails.plugins:views-json:1.0.0. Is it possible to render command object as a json result? Is it rendering only domain classes provided in a model?

I tried:

model {
    TrainingStatisticsCommand cmd
}

json.cmd {
    startDate cmd?.startDate
    endDate cmd?.endDate
    trainings tmpl.training(cmd?.trainings)
}

but I received:

{
    "cmd": {
        "startDate": null,
        "endDate": null,
        "trainings": null
    }
}

I'm executing it from controller as:

    respond cmd, [status: OK, view:"trainingsByClients"]

and cmd object has inside some data for sure.

1

There are 1 answers

1
Graeme Rocher On BEST ANSWER

You model would need to be

model {
   TrainingStatisticsCommand trainingStatisticsCommand
}

Or you would need to be explicit about the model variable name.