java - how do i format restful webservice json output so each json object starts on a new line? -


for reason, 1 of @get methods automatically outputs json data in following format while both implementations identical. want other @get method format output shown below.

get doctors code:

@path("/doctors") @get @produces(mediatype.application_json) public list<doctor> getalldoctors() throws exception{     return dao.getalldoctors(); } 

get patients code:

@path("/patients") @get @produces(mediatype.application_json) public list<patient> getallpatients() throws exception{     return dao.getallpatients(); } 

uniform output:

[{"specialty":"surgeon","sex":"male","experience":4,"salary":23232.66,"id":3,"firstname":"kobe","lastname":"bryant"}, {"specialty":"surgeon","sex":"male","experience":4,"salary":23232.66,"id":33,"firstname":"d","lastname":"bryant"}, {"specialty":"eyebrows","sex":"female","experience":1,"salary":1.0,"id":2,"firstname":"joan","lastname":"smith"}, {"specialty":"eyebrows","sex":"female","experience":1,"salary":1.0,"id":69,"firstname":"joan","lastname":"smith"}] 

there several approach so:

  • globally in responsefilter:

the idea override response content body , make pretty there. keep in mind jersey serialize object jackson internally.

  • directly in class:

you have change signature of rest method response type. serialize object manually via jackson objectmapper.

the step once have json obecjt prettify it. jacksonutils have method so.

i suggest add query string in order know if want have pretty output or not. more suitable.

let me know if want more detailed anserw.

hope helps,


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -