Adding List to Json ObjectNode

ObjectNode row = Json.newObject();
row.put("0", a);
row.put("1", x);
row.put("2", y);

I now have a list

List<String> list = new ArrayList<String>();

How to add this to a string?

+4
source share
1 answer

You can use the method putArraythat creates ArrayNode. Then you should fill it with elements from your list.

ArrayNode arrayNode = row.putArray("myList");
for (String item : list) {
    arrayNode.add(item);
}
+5
source

Source: https://habr.com/ru/post/1619624/


All Articles