My goal is to update some textual fields in a JsonNode.
List<JsonNode> list = json.findValues("fieldName");
for(JsonNode n : list){
// n is a TextNode. I'd like to change its value.
}
I don't see how this could be done. Do you have any suggestion?
Because you cannot modify a TextNode, you can instead get all the parentNodes of that field, and call the put operation on it with the same field name and a new value. It will replace the existing field and change the value.
The short answer is: you can't.
TextNode
does not expose any operations that allows you to alter the contents.With that being said, you can easily traverse the nodes in a loop or via recursion to get the desired behaviour. Imagine the following:
The output is: