I have a com.fasterxml JsonNode
object with some data. I need to do some manipulation on its data. I googled for answer but didn\'t got it properly. Can you please
I had this error too although in my case it was a stupid mistake.
I accidentally imported org.codehaus.jackson.node.ObjectNode
instead of com.fasterxml.jackson.databind.node.ObjectNode
.
Using the jackson ObjectNode fixed the issuse.
I try it some times, it will be ok! You only define a Student Class
to map the properties. Then you could convert the jsonNode
to Student
Object.
Student student = objectMapper.convertValue(jsonNode1, Student.class);
I think this will be suitable for your need!
You can convert a JsonNode
in an ObjectNode
in this simple way:
ObjectNode objectNode = jsonNode.deepCopy();
Available from Jackson 2.0 and tested with Jackson 2.4.0
Finally, I got the solution as follows...
JsonNode jsonNode = Json.toJson("Json String");
ObjectNode node = (ObjectNode) new ObjectMapper().readTree(jsonNode.asText());
//perform operations on node
jsonNode = (JsonNode) new ObjectMapper().readTree(node.toString());
or another one as below...
ObjectNode node = (ObjectNode) new ObjectMapper().readTree("Json String")
//perform operations on node
jsonNode = (JsonNode) new ObjectMapper().readTree(node.toString());
but I don't know if this is good approach or not ? If there is any better than above, please let me know. Thank you!