I have to encode gpstracks to json. They are stored in a mySql database, but getting them out auf there is quick, ~400ms. Encoding to json takes me 10s now, which is very ugly.
List<series> Tracks = new ArrayList<series>();
...
@Override
public String toString(){
    JsonObjectBuilder outerbuilder = Json.createObjectBuilder();
    //System.out.println("   TrackList::toString() 1: "+ZonedDateTime.now().toString());
    for (series s : Tracks){
        outerbuilder.add(s.Name, s.toArray());  
    }
    //System.out.println("   TrackList::toString() 1: "+ZonedDateTime.now().toString()); ~10s
    return outerbuilder.build().toString();
}
public class series {
    public JsonArray toArray(){
        JsonArrayBuilder array = Json.createArrayBuilder();
        for (sample s : samples){
            JsonArrayBuilder arrI = Json.createArrayBuilder(); //Building so many arrays has bad performance ~10s
            arrI.add(s.getLat());
            arrI.add(s.getLon());
            array.add(arrI.build());
            //array.add("["+s.getLat()+","+s.getLon()+"]"); // fast ~1s
            //{"854":["[47.6,11.8]","[47.6,11.8]"
            //is wrong should be:
            //{"854":[[47.6,11.8],[47.6,11.8],[4
        }
        return array.build();
    }
}
I would like to improve the performance. I tried to build a string directly, that takes 1s. Why is jsonbuilder so much slower and how can I use it right?
(Building a string directly would be possible of course, but I would like to use jsonbuilder if possible.
 
    