scala play 2.1 serve JSON response as text/json -
i'm running play! 2.2 scala. trying serve json response. following code serve response application/json, want serve text/json.
i found documentation here: http://www.playframework.com/documentation/2.1.x/scalajsonrequests however, examples shown return application/json.
here example of function in controller:
def mycontollerfunction = action(parse.json) { request => (request.body \ "foo").asopt[string].map { foo => ok(json.tojson(map("foo" -> foo))) }}.getorelse { badrequest("foo bar") } } here example output curl:
http/1.1 200 ok content-type: application/json; charset=utf-8
you can add .as("text/json") result. (see play documentation)
complete example:
def mycontollerfunction = action(parse.json) { request => (request.body \ "foo").asopt[string].map { foo => ok(json.tojson(map("foo" -> foo))).as("text/json") }}.getorelse { badrequest("foo bar") } } that being said, seems application/json correct type json data, see here.
Comments
Post a Comment