how to create insert new nodes in JsonNode?

后端 未结 2 920
温柔的废话
温柔的废话 2020-12-02 16:20

I have a new JsonNode that I created

JsonNode jNode = new ObjectCodec().createObjectNode();

with this node, how do I then add key value pai

相关标签:
2条回答
  • 2020-12-02 17:13

    I've recently found even more interesting way to create any ValueNode or ContainerNode (Jackson v2.3).

    ObjectNode node = JsonNodeFactory.instance.objectNode();
    
    0 讨论(0)
  • 2020-12-02 17:19

    These methods are in ObjectNode: the division is such that most read operations are included in JsonNode, but mutations in ObjectNode and ArrayNode.

    Note that you can just change first line to be:

    ObjectNode jNode = mapper.createObjectNode();
    // version ObjectMapper has should return ObjectNode type
    

    or

    ObjectNode jNode = (ObjectNode) objectCodec.createObjectNode();
    // ObjectCodec is in core part, must be of type JsonNode so need cast
    
    0 讨论(0)
提交回复
热议问题