jeudi 25 juin 2015

create json array from List using java json library

Is it possible to create a json format from List using Java json library without iteration over the List? This is what I do now and the performance is unacceptable with 2000 iteration. Any suggestion?

List<MyClass> list = MyDB.getAllItems();
JsonObjectBuilder builder = Json.createObjectBuilder();
        builder.add("success", true);
        JsonArrayBuilder childrenArrayBuilder = Json.createArrayBuilder();
        for(MyClass it : list){
             childrenArrayBuilder.add(
                        Json.createObjectBuilder()
                        .add("id", getTreeNodeId(it) + "-" + (idSplit[1]))
                        .add("nodeStatus", b)
                        .add("text", it.getName())
                        .add("leaf", false));
                }

Aucun commentaire:

Enregistrer un commentaire