Class Jackson2JsonRedisSerializer<T>
- All Implemented Interfaces:
RedisSerializer<T>
RedisSerializer that can read and write JSON using
Jackson's and
Jackson 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 Jackson2ObjectReader respective
Jackson2ObjectWriter.
- Since:
- 1.2
- Author:
- Thomas Darimont, Mark Paluch
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharsetDeprecated, for removal: This API element is subject to removal in a future version.since 3.0 for removal. -
Constructor Summary
ConstructorsConstructorDescriptionJackson2JsonRedisSerializer(com.fasterxml.jackson.databind.JavaType javaType) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJackson2JsonRedisSerializerfor the given targetJavaType.Jackson2JsonRedisSerializer(com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.databind.JavaType javaType) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJackson2JsonRedisSerializerfor the given targetJavaType.Jackson2JsonRedisSerializer(com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.databind.JavaType javaType, Jackson2ObjectReader reader, Jackson2ObjectWriter writer) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJackson2JsonRedisSerializerfor the given targetJavaType.Jackson2JsonRedisSerializer(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<T> type) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJackson2JsonRedisSerializerfor the given targetClass.Jackson2JsonRedisSerializer(Class<T> type) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJackson2JsonRedisSerializerfor the given targetClass. -
Method Summary
Modifier and TypeMethodDescription@Nullable Tdeserialize(byte @Nullable [] bytes) Deprecated, for removal: This API element is subject to removal in a future version.Deserialize an object from the given binary data.protected com.fasterxml.jackson.databind.JavaTypegetJavaType(Class<?> clazz) Deprecated, for removal: This API element is subject to removal in a future version.Returns the JacksonJavaTypefor the specific class.byte[]Deprecated, for removal: This API element is subject to removal in a future version.Serialize the given object to binary data.voidsetObjectMapper(com.fasterxml.jackson.databind.ObjectMapper mapper) Deprecated, for removal: This API element is subject to removal in a future version.since 3.0, useconstructor creationto configure the object mapper.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.redis.serializer.RedisSerializer
canSerialize, getTargetType
-
Field Details
-
DEFAULT_CHARSET
Deprecated, for removal: This API element is subject to removal in a future version.since 3.0 for removal.
-
-
Constructor Details
-
Jackson2JsonRedisSerializer
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJackson2JsonRedisSerializerfor the given targetClass.- Parameters:
type- must not be null.
-
Jackson2JsonRedisSerializer
public Jackson2JsonRedisSerializer(com.fasterxml.jackson.databind.JavaType javaType) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJackson2JsonRedisSerializerfor the given targetJavaType.- Parameters:
javaType- must not be null.
-
Jackson2JsonRedisSerializer
public Jackson2JsonRedisSerializer(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<T> type) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJackson2JsonRedisSerializerfor the given targetClass.- Parameters:
mapper- must not be null.type- must not be null.- Since:
- 3.0
-
Jackson2JsonRedisSerializer
public Jackson2JsonRedisSerializer(com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.databind.JavaType javaType) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJackson2JsonRedisSerializerfor the given targetJavaType.- Parameters:
mapper- must not be null.javaType- must not be null.- Since:
- 3.0
-
Jackson2JsonRedisSerializer
public Jackson2JsonRedisSerializer(com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.databind.JavaType javaType, Jackson2ObjectReader reader, Jackson2ObjectWriter writer) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJackson2JsonRedisSerializerfor the given targetJavaType.- Parameters:
mapper- must not be null.javaType- must not be null.reader- theJackson2ObjectReaderfunction to read objects usingObjectMapper.writer- theJackson2ObjectWriterfunction to write objects usingObjectMapper.- Since:
- 3.0
-
-
Method Details
-
setObjectMapper
@Deprecated(since="3.0", forRemoval=true) public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper mapper) Deprecated, for removal: This API element is subject to removal in a future version.since 3.0, useconstructor creationto configure the object mapper.Sets theObjectMapperfor this view. If not set, a defaultObjectMapperis used.Setting a custom-configured
ObjectMapperis one way to take further control of the JSON serialization process. For example, an extendedSerializerFactorycan be configured that provides custom serializers for specific types. The other option for refining the serialization process is to use Jackson's provided annotations on the types to be serialized, in which case a custom-configured ObjectMapper is unnecessary. -
serialize
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:RedisSerializerSerialize the given object to binary data.- Specified by:
serializein 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
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:RedisSerializerDeserialize an object from the given binary data.- Specified by:
deserializein interfaceRedisSerializer<T>- Parameters:
bytes- object binary representation. Can be null.- Returns:
- the equivalent object instance. Can be null.
- Throws:
SerializationException
-
getJavaType
Deprecated, for removal: This API element is subject to removal in a future version.Returns the JacksonJavaTypefor 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
-
JacksonJsonRedisSerializer.