From Java Object to JSON String using javax.json -
is possible create json string list<myclass>
using java ee 7's javax.json
library without iterating on list<myclass>
?
this , performance unacceptable 2000 iteration. suggestion?
list<myclass> items = mydb.getallitems(); jsonobjectbuilder builder = json.createobjectbuilder(); builder.add("success", true); jsonarraybuilder childrenarraybuilder = json.createarraybuilder(); (myclass item : items) { childrenarraybuilder.add( json.createobjectbuilder() .add("id", gettreenodeid(item) + "-" + (idsplit[1])) .add("nodestatus", b) .add("text", item.getname()) .add("leaf", false)); }
you creating lot of objects in loops not necessary. gson , far myclass
contains need like:
list<myclass> list = mydb.getallitems(); gson gson = new gson(); string mystring = gson.tojson(list);
Comments
Post a Comment