GRAILS respond with atomic json values

69 views Asked by At

I have actions that make sense to return an atomic value of json (user/hasPrivilege, etc) and would like my response to just contain "true" or "false", I'd also like to be able to send raw numbers and strings. I think these would count as valid json, but get the error:

Value out of sequence: expected mode to be OBJECT or ARRAY when writing 'false' but was INIT

Is it possible to instruct Grails to serialize these when the accept header is json?

1

There are 1 answers

1
alexanderfranke On BEST ANSWER

As those values are valid json it seems that the Groovy JsonOutput does convert them to a Json string:

import groovy.json.*
JsonOutput.toJson(true)
>>> true

So wouldn't it be possible to convert with JsonOutput and respond with that instead of the Grails as JSON?