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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -