Interface RedisSerializer<T>
- All Known Implementing Classes:
GenericJackson2JsonRedisSerializer
,GenericToStringSerializer
,Jackson2JsonRedisSerializer
,JdkSerializationRedisSerializer
,OxmSerializer
,StringRedisSerializer
public interface RedisSerializer<T>
Basic interface serialization and deserialization of Objects to byte arrays (binary data). It is recommended that
implementations are designed to handle null objects/empty arrays on serialization and deserialization
side. Note that Redis does not accept null keys or values but can return null replies (for non-existing
keys).
- Author:
- Mark Pollack, Costin Leau, Christoph Strobl
-
Method Summary
Modifier and TypeMethodDescriptionstatic RedisSerializer<byte[]>
Obtain aRedisSerializer
that passes thrubyte[]
.default boolean
canSerialize
(Class<?> type) Check whether the given valuetype
can be serialized by this serializer.deserialize
(byte[] bytes) Deserialize an object from the given binary data.default Class<?>
Return the serializer target type.static RedisSerializer<Object>
java()
Obtain aRedisSerializer
using java serialization.static RedisSerializer<Object>
java
(ClassLoader classLoader) Obtain aRedisSerializer
using java serialization with the givenClassLoader
.static RedisSerializer<Object>
json()
Obtain aRedisSerializer
that can read and write JSON using Jackson.byte[]
Serialize the given object to binary data.static RedisSerializer<String>
string()
-
Method Details
-
java
Obtain aRedisSerializer
using java serialization. Note: Ensure that your domain objects are actuallyserializable
.- Returns:
- never null.
- Since:
- 2.1
-
java
Obtain aRedisSerializer
using java serialization with the givenClassLoader
. Note: Ensure that your domain objects are actuallyserializable
.- Parameters:
classLoader
- theClassLoader
to use for deserialization. Can be null.- Returns:
- new instance of
RedisSerializer
. Never null. - Since:
- 2.1
-
json
Obtain aRedisSerializer
that can read and write JSON using Jackson.- Returns:
- never null.
- Since:
- 2.1
-
string
- Returns:
- never null.
- Since:
- 2.1
-
byteArray
Obtain aRedisSerializer
that passes thrubyte[]
.- Returns:
- never null.
- Since:
- 2.2
-
serialize
Serialize the given object to binary data.- Parameters:
value
- object to serialize. Can be null.- Returns:
- the equivalent binary data. Can be null.
- Throws:
SerializationException
-
deserialize
Deserialize an object from the given binary data.- Parameters:
bytes
- object binary representation. Can be null.- Returns:
- the equivalent object instance. Can be null.
- Throws:
SerializationException
-
canSerialize
Check whether the given valuetype
can be serialized by this serializer.- Parameters:
type
- the value type.- Returns:
true
if the value type can be serialized;false
otherwise.
-
getTargetType
Return the serializer target type.- Returns:
- the serializer target type.
-