Jackson JSON与JsonNode和ObjectNode之间的区别 [英] Jackson JSON difference between JsonNode and ObjectNode

查看:290
本文介绍了Jackson JSON与JsonNode和ObjectNode之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jackson进行JSON解析。
JsonNode和ObjectNode之间有什么区别。



用于以字符串格式映射json。

解决方案

快速回答






  • I am using Jackson for JSON parsing. What is the difference between JsonNode and ObjectNode.

    And which to use for mapping json in string format.

    解决方案

    Quick answer

    • JsonNode: Abstract class, used when reading a JSON document.
    • ObjectNode: Concrete implementation, used when building or modifying a JSON document.

    Keep reading for a more detailed answer.

    JsonNode

    JsonNode is an abstract class used as the base class for all JSON nodes, which form the basis of JSON Tree Model that Jackson implements.

    Quoting the JsonNode documentation:

    As a general design rule, most accessors (getters) methods are included in this base class, to allow for traversing structure without type casts.

    Mutators methods (setters), however, need to be accessed through specific sub-classes (such as ObjectNode and ArrayNode).

    This seems sensible because proper type information is generally available when building or modifying trees, but less often when reading a tree (newly built from parsed JSON content).

    The JsonNode concrete implementations can be found in the com.fasterxml.jackson.databind.node package.

    ObjectNode

    ObjectNode is a concrete implementation of JsonNode that maps a JSON object and a JSON object is defined as following:

    An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).

    这篇关于Jackson JSON与JsonNode和ObjectNode之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆