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) deserialize
(byte[] bytes) Deserialize an object from the given binary data.default Class<?>
static RedisSerializer<Object>
java()
Obtain aRedisSerializer
using java serialization.
Note: Ensure that your domain objects are actuallyserializable
.static RedisSerializer<Object>
java
(ClassLoader classLoader) Obtain aRedisSerializer
using java serialization with the givenClassLoader
.
Note: Ensure that your domain objects are actuallyserializable
.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
-
serialize
Serialize the given object to binary data.- Parameters:
t
- 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
-
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
-
canSerialize
-
getTargetType
-