jcakson3构建ObjectMapper开源
开源地址
https://github.com/NekoNekoCloud/article-like-vote
自springboot4.0开始,Jackson2JsonRedisSerializer就被移除,支持JacksonJsonRedisSerializer
JacksonJsonRedisSerializer是一个可以使用 Jackson 3 和 Jackson 3 Databind 的 ObjectMapper 读写 JSON 的 Redis 序列化器。
该序列化器可用于绑定到类型化的 Bean,或非类型化的 HashMap 实例。注意:空对象会被序列化为空数组,反之亦然(即空数组也会被反序列化为空对象)。
可以通过配置 JacksonObjectReader 和 JacksonObjectWriter 来分别定制 JSON 的读取和写入行为。”
RedisSerializer that can read and write JSON using Jackson 3 and Jackson 3 Databind . ObjectMapper
This serializer can be used to bind to typed beans, or untyped HashMap instances. Note:Null objects are serialized as empty arrays and vice versa.
JSON reading and writing can be customized by configuring JacksonObjectReader respective JacksonObjectWriter.
在 Spring 博客的《Introducing Jackson 3 support in Spring》中明确写道:
Jackson 3 introduces a lot of changes and enhancements, but from a Spring perspective one of the most important ones to understand and embrace is the switch from a mutable
ObjectMapperin Jackson 2 to an immutableJsonMapperin Jackson 3.
JsonMapper, which extendsObjectMapper, is specific to the JSON format, following a similar pattern than other formats (XmlMapper,YAMLMapper,SmileMapper, etc.) and Spring support has been updated to use this format specific variant, following Jackson 3 best practices.Also with Jackson and Spring defaults mostly aligned, and the introduction of a first class
JsonMapper.Builder, Spring Framework does not provide an equivalent forJackson2ObjectMapperBuilder, you should just use the Jackson builder.
这段话直接点明了:Jackson 2 的 ObjectMapper 是可变的,而 Jackson 3 的 JsonMapper 是不可变的,必须使用 Builder 构建。