How to convert JsonNode to ObjectNode

前端 未结 4 1810
误落风尘
误落风尘 2021-02-05 03:51

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

4条回答
  •  我寻月下人不归
    2021-02-05 04:43

    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!

提交回复
热议问题