Jackson:项目结构分析

边浩波
2023-12-01

目录

1、核心modules

2、datatype modules

3、JAX-RS(Java API for RESTful Web Services)支持

4、Data format modules

5、JVM系语言支持


作为java体系下标准的json函数库,目前默认被应用在spring boot中。jackson是一套用于Java和JVM平台的数据处理工具,包括流式json解析器/生成器函数库、数据绑定函数库(POJO和JSON的互转),以及用以处理Avro,BSON,CBOR,CSV,Smile,(Java)Properties,Protobuf,XML,和YAML编码的数据格式化模块。还有很多的数据格式模块用以支持更广泛的数据类型,诸如Guava,Joda,PCollections中的更多其他的数据类型也是支持转换的。

1、核心modules

实际的核心组件属于他们自己的项目下-包括三个核心程序包(streaming【core】,databind,annotations),数据格式(dataformat)函数库,数据类型(datatype)库,JAX-RS(提供JSON、Smile【binary JSON】、CBOR【another kind of binary JSON】、XML、YAML的自动注册)

核心modules

  1. Streaming(jackson-core):定义了较低级别的流式API,并包含JSON的特定实现
  2. Annotations(jackson-annotations):包含jackson的标准注解
  3. Databind(jackson-databind):在Streaming包上实现了数据绑定和对象序列化,它依赖于以上两个包

2、datatype modules

支持第三方数据类型的modules

这些扩展作为jackson的module的插件(以ObjectMapper.registerModule()的方式),并通过添加序列化器和反序列化器来支持常用java库的数据类型,以便databind包(objectMapper,objectReader,objectWriter)能够对这些类型进行读写。

以下这些数据类型包是由jackson团队进行维护的:

此外,jackson团队并未直接维护的modules:

3、JAX-RS(Java API for RESTful Web Services)支持

Jackson JAX-RS Providers has handlers to add dataformat support for JAX-RS implementations (like Jersey, RESTeasy, CXF). Providers implement MessageBodyReader and MessageBodyWriter. Supported formats currently include JSONSmileXMLYAML and CBOR.

4、Data format modules

Data format modules 提供了除json外的其他格式支持。大部分都是简单继承了streaming的api,所以databinding组件可以使用。

  • Avro: supports Avro data format, with streaming implementation plus additional databind-level support for Avro Schemas
  • CBOR: supports CBOR data format (a binary JSON variant).
  • CSV: supports Comma-separated values format -- streaming api, with optional convenience databind additions
  • Ion (NEW with Jackson 2.9!): support for Amazon Ion binary data format (similar to CBOR, Smile, i.e. binary JSON - like)
  • (Java) Properties (2.8): creating nested structure out of implied notation (dotted by default, configurable), flattening similarly on serialization
  • Protobuf (2.6): supported similar to Avro
  • Smile: supports Smile (binary JSON) -- 100% API/logical model compatible via streaming API, no changes for databind
  • XML: supports XML; provides both streaming and databind implementations. Similar to JAXB' "code-first" mode (no support for "XML Schema first", but can use JAXB beans)
  • YAML: supports YAML, which being similar to JSON is fully supported with simple streaming implementation

另外,还有一些由其他人员开发的data format 的modules:

  • BEncode: support for reading/writing BEncode (BitTorrent format) encoded data
  • bson4jackson: adds support for BSON data format (by Mongo project).
    • Implemented as full streaming implementation, which allows full access (streaming, data-binding, tree-model)
    • Also see [MongoJack] library below; while not a dataformat module, it allows access to BSON data as well.
  • EXIficient supports Efficient XML Interchange
  • jackson-dataformat-msgpack adds support MessagePack (aka MsgPack) format
    • Implemented as full streaming implementation, which allows full access (streaming, data-binding, tree-model)
  • HOCON: experimental, partial implementation to support HOCON format -- work in progress
  • Rison: Jackson backend to support Rison)

5、JVM系语言支持

  • Kotlin to handle native types of Kotlin
  • Scala to handle native Scala types (including but not limited to Scala collection/map types, case classes)
    • Currently (April 2020) Scala 2.10, 2.11, 2.12 and 2.13 are supported (2.9 was supported up to Jackson 2.3)
 类似资料: