Class Jackson3JsonRedisSerializer<T>
java.lang.Object
org.springframework.data.redis.serializer.Jackson3JsonRedisSerializer<T>
- All Implemented Interfaces:
RedisSerializer<T>
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 Jackson3ObjectReader
respective
Jackson3ObjectWriter
.
- Since:
- 4.0
- Author:
- Christoph Strobl, Thomas Darimont, Mark Paluch
-
Constructor Summary
ConstructorsConstructorDescriptionJackson3JsonRedisSerializer
(Class<T> type) Creates a newJackson3JsonRedisSerializer
for the given targetClass
.Jackson3JsonRedisSerializer
(tools.jackson.databind.JavaType javaType) Creates a newJackson3JsonRedisSerializer
for the given targetJavaType
.Jackson3JsonRedisSerializer
(tools.jackson.databind.ObjectMapper mapper, Class<T> type) Creates a newJackson3JsonRedisSerializer
for the given targetClass
.Jackson3JsonRedisSerializer
(tools.jackson.databind.ObjectMapper mapper, tools.jackson.databind.JavaType javaType) Creates a newJackson3JsonRedisSerializer
for the given targetJavaType
.Jackson3JsonRedisSerializer
(tools.jackson.databind.ObjectMapper mapper, tools.jackson.databind.JavaType javaType, Jackson3ObjectReader reader, Jackson3ObjectWriter writer) Creates a newJackson3JsonRedisSerializer
for the given targetJavaType
. -
Method Summary
Modifier and TypeMethodDescription@Nullable T
deserialize
(byte @Nullable [] bytes) Deserialize an object from the given binary data.protected tools.jackson.databind.JavaType
getJavaType
(Class<?> clazz) Returns the JacksonJavaType
for the specific class.byte[]
Serialize the given object to binary data.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.data.redis.serializer.RedisSerializer
canSerialize, getTargetType
-
Constructor Details
-
Jackson3JsonRedisSerializer
Creates a newJackson3JsonRedisSerializer
for the given targetClass
.- Parameters:
type
- must not be null.
-
Jackson3JsonRedisSerializer
public Jackson3JsonRedisSerializer(tools.jackson.databind.JavaType javaType) Creates a newJackson3JsonRedisSerializer
for the given targetJavaType
.- Parameters:
javaType
- must not be null.
-
Jackson3JsonRedisSerializer
Creates a newJackson3JsonRedisSerializer
for the given targetClass
.- Parameters:
mapper
- must not be null.type
- must not be null.
-
Jackson3JsonRedisSerializer
public Jackson3JsonRedisSerializer(tools.jackson.databind.ObjectMapper mapper, tools.jackson.databind.JavaType javaType) Creates a newJackson3JsonRedisSerializer
for the given targetJavaType
.- Parameters:
mapper
- must not be null.javaType
- must not be null.
-
Jackson3JsonRedisSerializer
public Jackson3JsonRedisSerializer(tools.jackson.databind.ObjectMapper mapper, tools.jackson.databind.JavaType javaType, Jackson3ObjectReader reader, Jackson3ObjectWriter writer) Creates a newJackson3JsonRedisSerializer
for the given targetJavaType
.- Parameters:
mapper
- must not be null.javaType
- must not be null.reader
- theJackson3ObjectReader
function to read objects usingObjectMapper
.writer
- theJackson3ObjectWriter
function to write objects usingObjectMapper
.
-
-
Method Details
-
serialize
Description copied from interface:RedisSerializer
Serialize the given object to binary data.- Specified by:
serialize
in interfaceRedisSerializer<T>
- Parameters:
value
- object to serialize. Can be null.- Returns:
- the equivalent binary data. Can be an empty array but never null.
- Throws:
SerializationException
-
deserialize
Description copied from interface:RedisSerializer
Deserialize an object from the given binary data.- Specified by:
deserialize
in interfaceRedisSerializer<T>
- Parameters:
bytes
- object binary representation. Can be null.- Returns:
- the equivalent object instance. Can be null.
- Throws:
SerializationException
-
getJavaType
Returns the JacksonJavaType
for the specific class.Default implementation returns
TypeFactory.constructType(java.lang.reflect.Type)
, but this can be overridden in subclasses, to allow for custom generic collection handling. For instance:protected JavaType getJavaType(Class<?> clazz) { if (List.class.isAssignableFrom(clazz)) { return TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, MyBean.class); } else { return super.getJavaType(clazz); } }
- Parameters:
clazz
- the class to return the java type for- Returns:
- the java type
-