user375566
user375566

Reputation:

Rendering JSON response string in Java Controller like a Scala Controller

In a Scala controller, I can simply render a response (for dev pursposes) using the magical """:

Ok("""{"key":"value"}"""} 

In a Java controller, this obviously doesn't work. Is there a quick way to render a JSON string as a response? (that is too long to escape manually without hitting my head against a wall)

I don't want to do:

ok("{\"key\":\"value\"}");

Upvotes: 2

Views: 227

Answers (2)

Ilya
Ilya

Reputation: 29693

No. """ it's feature from Scala and Groovy programming languages. In Java no analogue.
You can try

ok("{'key':'value'}");  

but it does not always work

Upvotes: 1

Kim Stebel
Kim Stebel

Reputation: 42047

The only way I see is to write a small shell script or scala script to do the escaping for you and then copy/paste the output of that into your java file.

Upvotes: 0

Related Questions