Java Play FrameWork 2.3 return streamed Json using jackson -
is there way can stream json in api response?
i understand how can read , write json file using jackson library example:
http://www.mkyong.com/java/jackson-streaming-api-to-read-and-write-json/
but in play framework, how can stream response or in other words return in api intead of return ok();
?
have tried play's chunked responses?
in controller have action on line:
public result chunkedjson() { return ok(readjsonchunks()); }
and in readjsonchunks
method create chunks:
public static chunks<string> readjsonchunks() { chunks<string> chunks = new stringchunks() { @override public void onready(play.mvc.results.chunks.out<string> out) { jsonfactory jfactory = new jsonfactory(); try { // read file jsonparser jparser = jfactory.createjsonparser(new file("c:\\user.json")); // loop until token equal "}" while (jparser.nexttoken() != jsontoken.end_object) { // write json stuff out, e.g. string text = jparser.gettext(); out.write(text); } jparser.close(); } catch (ioexception e) { out.write("couldn't open file c:\\user.json"); } { out.close(); } } }; return chunks; }
i've never tried particular code (especially i've never used jsonfactory.createjsonparser - seems deprecated) use similar send log files server client.
(i'm working play 2.2.3)
Comments
Post a Comment