ObjectNode row = Json.newObject();
row.put("0", a);
row.put("1", x);
row.put("2", y);
now I have list
List<String> list = new ArrayList<String>();
How can I add this to the row?
You can use the putArray method which creates an ArrayNode . Then you should fill it with the elements from your list. addAll expects an ArrayNode or a liste of JsonObjects, you'll want to iterate through your list to add its strings to the new ArrayNode. @EricMaziade, you are right.
JsonNode represents any valid Json structure whereas ObjectNode and ArrayNode are particular implementations for objects (aka maps) and arrays, respectively.
You can use the putArray
method which creates an ArrayNode
. Then you should fill it with the elements from your list.
ArrayNode arrayNode = row.putArray("myList");
for (String item : list) {
arrayNode.add(item);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With