java – ObjectMapper(). Createobjectnode and jsonnodefactory instance. What is the difference between objectnode()?

I saw a post about inserting a new node into jsonnode and encountered two separate answers, but I couldn't understand the difference between the two

In my experience, objectmapper does not allow you to create anything except objectnode and arraynode, while jsonnodefactory allows you to create a whole bunch of nodes

What are the other differences?

In addition, since objectmapper is considered expensive, I wonder whether the latter method is more effective?

Solution

There is no difference between the following methods:

ObjectMapper mapper = new ObjectMapper();
ObjectNode objectNode = mapper.createObjectNode();
ObjectNode objectNode = JsonNodeFactory.instance.objectNode();

Behind the scenes, Jackson will delegate the createobjectnode () method to jsonnodefactory

For more details on how to use jsonnodefactory, see this answer

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>