目录
3、JAX-RS(Java API for RESTful Web Services)支持
作为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
- Streaming(jackson-core):定义了较低级别的流式API,并包含JSON的特定实现
- Annotations(jackson-annotations):包含jackson的标准注解
- Databind(jackson-databind):在Streaming包上实现了数据绑定和对象序列化,它依赖于以上两个包
2、datatype modules
支持第三方数据类型的modules
这些扩展作为jackson的module的插件(以ObjectMapper.registerModule()的方式),并通过添加序列化器和反序列化器来支持常用java库的数据类型,以便databind包(objectMapper,objectReader,objectWriter)能够对这些类型进行读写。
以下这些数据类型包是由jackson团队进行维护的:
- 标准的集合( Collections )数据类型modules:
- jackson-datatype-eclipse-collections: support for Eclipse Collections (NEW in Jackson 2.10!)
- jackson-datatype-guava: support for many of Guava datatypes
- jackson-datatype-hppc: support for High-Performance Primitive Containers containers
- jackson-datatype-pcollections: support for PCollections datatypes (since Jackson 2.7)
- Hibernate: support for Hibernate features (lazy-loading, proxies)
- Java 8 Modules: support or JDK 8 features and datatypes through 3 separate modules
jackson-module-parameter-names
: Module that adds support for using a new JDK8 feature, ability to access names of constructor and method parameters, to allow omitting@JsonProperty
.jackson-datatype-jsr310
: support for "Java 8 Dates" (ones added in JDK 8)- Also, for pre-Java8 users can use one of alternate pre-Java8 backports:
jackson-datatype-jdk8
: support for JDK 8 data types other than date/time types, includingOptional
- Joda datatypes:
- jackson-datatype-joda: support for types of Joda-Time date/time library datatypes
- jackson-datatype-joda-money: support types of Joda-Money datatypes (
Money
,CurrencyUnit
)
- jackson-datatype-jsr353: support for JSON-P ("Java JSON API") types (specifically its tree model objects)
- jackson-datatype-json-org: support for org.json library types like
JSONObject
,JSONArray
此外,jackson团队并未直接维护的modules:
- jackson-datatype-bolts support for reading/writing types defined by Yandex Bolts collection types (Functional Programming inspired immutable collections)
- jackson-datatype-commons-lang3 for types of Apache Commons Lang v3
- jackson-datatype-money for "Java Money", see javax.money
- javaslang-jackson for Javaslang support (Feature-rich & self-contained functional programming in Java™ 8 and above)
- jackson-datatype-json-lib for supporting types defined by "net.sf.json" library (aka "json-lib")
- jackson-datatype-jts (JTS Geometry) for GeoJSON support
- jackson-lombok for better support of Lombok classes
- jackson-datatype-mongo for MongoDB types
- NOTE: there are a few alternatives to handling MongoDB datatypes
- jackson-module-objectify for datatypes of Objectify
- jackson-datatype-protobuf for handling datatypes defined by the standard Java protobuf library, developed by HubSpot
- NOTE! This is different from
jackson-dataformat-protobuf
which adds support for encoding/decoding protobuf content but which does NOT depend on standard Java protobuf library
- NOTE! This is different from
- TinyTypes includes Jackson module (group id
com.github.caligin.tinytypes
, artifacttinytypes-jackson
) - jackson-datatype-vertx for reading/writing Vert.x
org.vertx.java.core.json.JsonObject
objects (repackagedorg.json
node types)
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 JSON
, Smile
, XML
, YAML
and CBOR
.
4、Data format modules
Data format modules 提供了除json外的其他格式支持。大部分都是简单继承了streaming的api,所以databinding组件可以使用。
- Avro: supports Avro data format, with
streaming
implementation plus additionaldatabind
-level support for Avro Schemas - CBOR: supports CBOR data format (a binary JSON variant).
- CSV: supports Comma-separated values format --
streaming
api, with optional conveniencedatabind
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 fordatabind
- XML: supports XML; provides both
streaming
anddatabind
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)