私のコントローラーは次のようになります。
def save() {
js {
def color = new Color(params)
color.save()
def result
if (!color.hasErrors())
{
result = [colorname: color.name, colorshde: color.shade]
}
else
{
result = "..."
}
render result as JSON
}
}
私が望む JSON は次のようになります。
成功した JSON
{
"meta": {
"status": 200,
"msg": "OK"
},
"response": {
"color": {
"colorname": "Red",
"shade": "light
}
}
}
失敗した応答:
{
"meta": {
"status": 400,
"msg": "Something went worn"
},
"response": {
"color": {
}
}
}
質問
json を返すときに両方のシナリオを考慮してコントローラー アクションを変更するにはどうすればよいですか?