简体   繁体   中英

Converting Map<Enum, Object> to JSON

I build a json on server like that:

List<Object> resp = new ArrayList<>();
for (String str : buffer.toString().split("\\n")) {
    for (String data : str.split("\\s")) {
        if (data.matches("[\\w|\\W]+") && !data.isEmpty()) {
            Child.set(Child.children, "null");
            Child.set(Child.parent, chain.name());
            Child.set(Child.name, data);
        }
        Child.setChild(Child.get());
    }
}

Child.set(Child.children, Child.getChild().toArray());
Child.set(Child.parent, "null");
Child.set(Child.name, chain.name());

The problem is that Child is HashMap<Child, Object> but when I put Child.set(Child.children, Child.getChild().toArray()); to Map and then convert the Map object with Google Gson to Json it breaks with error:

oejw.WebSocketConnectionRFC6455:java.lang.StackOverflowError

The problem is not with WebSocket I think, because when I'm previous convert to json the Child.getChild().toArray() and then put it to the map, there are no any errors, but the generated json is not fully corrected.

The problem was with converting to Json. Gson converts with stack overflow error. Solves with using JSONObject and JSONArray.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM