Class GenericJackson3JsonRedisSerializer
java.lang.Object
org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializer
- All Implemented Interfaces:
RedisSerializer<Object>
Generic Jackson 3-based
RedisSerializer
that maps objects
to and from JSON.
JSON reading and writing can be customized by configuring a Jackson3ObjectReader
and
Jackson3ObjectWriter
.
- Since:
- 4.0
- Author:
- Christoph Strobl
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
GenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder<B extends tools.jackson.databind.cfg.MapperBuilder<? extends tools.jackson.databind.ObjectMapper, ? extends tools.jackson.databind.cfg.MapperBuilder<?,
?>>> GenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder
wraps around aJsonMapper.Builder
providing dedicated methods to configure aspects likeNullValue
serialization strategy for the resultingObjectMapper
to be used withGenericJackson3JsonRedisSerializer
as well as potential Object/-reader
and-writer
settings. -
Constructor Summary
ConstructorsModifierConstructorDescriptionGenericJackson3JsonRedisSerializer
(tools.jackson.databind.ObjectMapper mapper) Create aGenericJackson3JsonRedisSerializer
with a custom-configuredObjectMapper
.protected
GenericJackson3JsonRedisSerializer
(tools.jackson.databind.ObjectMapper mapper, Jackson3ObjectReader reader, Jackson3ObjectWriter writer) Create aGenericJackson3JsonRedisSerializer
with a custom-configuredObjectMapper
considering potential Object/-reader
and-writer
. -
Method Summary
Modifier and TypeMethodDescriptionstatic GenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder
<tools.jackson.databind.json.JsonMapper.Builder> builder()
Creates a newGenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder
to configure and build aGenericJackson3JsonRedisSerializer
usingJsonMapper
.static <B extends tools.jackson.databind.cfg.MapperBuilder<? extends tools.jackson.databind.ObjectMapper, ? extends tools.jackson.databind.cfg.MapperBuilder<?,
?>>>
GenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder<B> Creates a newGenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder
to configure and build aGenericJackson3JsonRedisSerializer
.create
(Consumer<GenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder<tools.jackson.databind.json.JsonMapper.Builder>> configurer) Prepare a newGenericJackson3JsonRedisSerializer
instance.@Nullable Object
deserialize
(byte @Nullable [] source) Deserialize an object from the given binary data.<T> @Nullable T
deserialize
(byte @Nullable [] source, Class<T> type) protected tools.jackson.databind.JavaType
resolveType
(byte[] source, Class<?> type) 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
-
GenericJackson3JsonRedisSerializer
public GenericJackson3JsonRedisSerializer(tools.jackson.databind.ObjectMapper mapper) Create aGenericJackson3JsonRedisSerializer
with a custom-configuredObjectMapper
.- Parameters:
mapper
- must not be null.
-
GenericJackson3JsonRedisSerializer
protected GenericJackson3JsonRedisSerializer(tools.jackson.databind.ObjectMapper mapper, Jackson3ObjectReader reader, Jackson3ObjectWriter writer) Create aGenericJackson3JsonRedisSerializer
with a custom-configuredObjectMapper
considering potential Object/-reader
and-writer
.- Parameters:
mapper
- must not be null.reader
- theJackson3ObjectReader
function to read objects usingObjectMapper
.writer
- theJackson3ObjectWriter
function to write objects usingObjectMapper
.
-
-
Method Details
-
create
public static GenericJackson3JsonRedisSerializer create(Consumer<GenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder<tools.jackson.databind.json.JsonMapper.Builder>> configurer) Prepare a newGenericJackson3JsonRedisSerializer
instance.- Parameters:
configurer
- the configurer forGenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder
.- Returns:
- new instance of
GenericJackson3JsonRedisSerializer
.
-
builder
public static GenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder<tools.jackson.databind.json.JsonMapper.Builder> builder()Creates a newGenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder
to configure and build aGenericJackson3JsonRedisSerializer
usingJsonMapper
. -
builder
public static <B extends tools.jackson.databind.cfg.MapperBuilder<? extends tools.jackson.databind.ObjectMapper, ? extends tools.jackson.databind.cfg.MapperBuilder<?,?>>> GenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder<B> builder(Supplier<B> builderFactory) Creates a newGenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder
to configure and build aGenericJackson3JsonRedisSerializer
.- Type Parameters:
B
- type of theMapperBuilder
to use.- Parameters:
builderFactory
- factory to create aMapperBuilder
for theObjectMapper
.- Returns:
- a new
GenericJackson3JsonRedisSerializer.GenericJackson3JsonRedisSerializerBuilder
.
-
serialize
@Contract("_ -> !null") public byte[] serialize(@Nullable Object value) throws SerializationException Description copied from interface:RedisSerializer
Serialize the given object to binary data.- Specified by:
serialize
in interfaceRedisSerializer<Object>
- Parameters:
value
- object to serialize. Can be null.- Returns:
- the equivalent binary data. Can be an empty array but never null.
- Throws:
SerializationException
-
deserialize
@Contract("null -> null") public @Nullable Object deserialize(byte @Nullable [] source) throws SerializationException Description copied from interface:RedisSerializer
Deserialize an object from the given binary data.- Specified by:
deserialize
in interfaceRedisSerializer<Object>
- Parameters:
source
- object binary representation. Can be null.- Returns:
- the equivalent object instance. Can be null.
- Throws:
SerializationException
-
deserialize
@Contract("null, _ -> null") public <T> @Nullable T deserialize(byte @Nullable [] source, Class<T> type) throws SerializationException - Parameters:
source
- array of bytes containing the JSON to deserialize; can be null.type
-type
ofObject
from which the JSON will be deserialized; must not be null.- Returns:
- null for an empty source, or an
Object
of the giventype
deserialized from the array of bytes containing JSON. - Throws:
IllegalArgumentException
- if the giventype
is null.SerializationException
- if the array of bytes cannot be deserialized as an instance of the giventype
-
resolveType
protected tools.jackson.databind.JavaType resolveType(byte[] source, Class<?> type) throws IOException - Throws:
IOException
-