게시 요청에 대한 모든 JSON 응답에 success
필드를 포함하고 싶습니다. 이 필드를 추가하는 가장 좋은 방법은 무엇입니까?Grails JSON 응답에 추가 필드를 추가하는 방법이 있습니까?
try {
def entity = myService.saveEntity(arg1,arg2)
render [ success:'yes', val:entity ] as JSON
} catch (ValidationException e) {
render [ success:'no', val:parseErrors(e.errors) ] as JSON
}
그것을 테스트하지 :
try {
def entity = myService.saveEntity(arg1,arg2)
render entity as JSON //I want to add artificial field 'success = "yes"' here
} catch (ValidationException e) {
render parseErrors(e.errors) as JSON //field 'success = "no"' here
}
가장 간단한 해결책입니다. 나는 이것이 받아 들여진 대답이라고 투표한다. – mastaBlasta