Class GenericJackson2JsonRedisSerializer

java.lang.Object
org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer
All Implemented Interfaces:
RedisSerializer<Object>

public class GenericJackson2JsonRedisSerializer extends Object implements RedisSerializer<Object>
Generic Jackson 2-based RedisSerializer that maps objects to and from JSON using dynamic typing.

JSON reading and writing can be customized by configuring a JacksonObjectReader and JacksonObjectWriter.

Since:
1.6
Author:
Christoph Strobl, Mark Paluch, Mao Shuai, John Blum, Anne Lee
See Also:
  • Constructor Details

    • GenericJackson2JsonRedisSerializer

      public GenericJackson2JsonRedisSerializer()
      Creates GenericJackson2JsonRedisSerializer initialized with an ObjectMapper configured for default typing.
    • GenericJackson2JsonRedisSerializer

      public GenericJackson2JsonRedisSerializer(@Nullable String typeHintPropertyName)
      Creates GenericJackson2JsonRedisSerializer initialized with an ObjectMapper configured for default typing using the given name.

      In case name is empty or null, then JsonTypeInfo.Id.CLASS will be used.

      Parameters:
      typeHintPropertyName - name of the JSON property holding type information; can be null.
      See Also:
      • ObjectMapper.activateDefaultTypingAsProperty(PolymorphicTypeValidator, DefaultTyping, String)
      • ObjectMapper.activateDefaultTyping(PolymorphicTypeValidator, DefaultTyping, As)
    • GenericJackson2JsonRedisSerializer

      public GenericJackson2JsonRedisSerializer(@Nullable String typeHintPropertyName, JacksonObjectReader reader, JacksonObjectWriter writer)
      Creates GenericJackson2JsonRedisSerializer initialized with an ObjectMapper configured for default typing using the given name along with the given, required JacksonObjectReader and JacksonObjectWriter used to read/write Objects de/serialized as JSON.

      In case name is empty or null, then JsonTypeInfo.Id.CLASS will be used.

      Parameters:
      typeHintPropertyName - name of the JSON property holding type information; can be null.
      reader - JacksonObjectReader function to read objects using ObjectMapper.
      writer - JacksonObjectWriter function to write objects using ObjectMapper.
      Since:
      3.0
      See Also:
      • ObjectMapper.activateDefaultTypingAsProperty(PolymorphicTypeValidator, DefaultTyping, String)
      • ObjectMapper.activateDefaultTyping(PolymorphicTypeValidator, DefaultTyping, As)
    • GenericJackson2JsonRedisSerializer

      public GenericJackson2JsonRedisSerializer(com.fasterxml.jackson.databind.ObjectMapper mapper)
      Setting a custom-configured ObjectMapper is one way to take further control of the JSON serialization process. For example, an extended SerializerFactory can be configured that provides custom serializers for specific types.
      Parameters:
      mapper - must not be null.
    • GenericJackson2JsonRedisSerializer

      public GenericJackson2JsonRedisSerializer(com.fasterxml.jackson.databind.ObjectMapper mapper, JacksonObjectReader reader, JacksonObjectWriter writer)
      Setting a custom-configured ObjectMapper is one way to take further control of the JSON serialization process. For example, an extended SerializerFactory can be configured that provides custom serializers for specific types.
      Parameters:
      mapper - must not be null.
      reader - the JacksonObjectReader function to read objects using ObjectMapper.
      writer - the JacksonObjectWriter function to write objects using ObjectMapper.
      Since:
      3.0
  • Method Details