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 aRedisSerializerthat passes thrubyte[].default booleancanSerialize(Class<?> type) Check whether the given valuetypecan 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 aRedisSerializerusing java serialization.static RedisSerializer<Object>java(ClassLoader classLoader) Obtain aRedisSerializerusing java serialization with the givenClassLoader.static RedisSerializer<Object>json()Obtain aRedisSerializerthat can read and write JSON using Jackson.byte[]Serialize the given object to binary data.static RedisSerializer<String>string()
-
Method Details
-
java
Obtain aRedisSerializerusing java serialization. Note: Ensure that your domain objects are actuallyserializable.- Returns:
- never null.
- Since:
- 2.1
-
java
Obtain aRedisSerializerusing java serialization with the givenClassLoader. Note: Ensure that your domain objects are actuallyserializable.- Parameters:
classLoader- theClassLoaderto use for deserialization. Can be null.- Returns:
- new instance of
RedisSerializer. Never null. - Since:
- 2.1
-
json
Obtain aRedisSerializerthat can read and write JSON using Jackson.- Returns:
- never null.
- Since:
- 2.1
-
string
- Returns:
- never null.
- Since:
- 2.1
-
byteArray
Obtain aRedisSerializerthat 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 valuetypecan be serialized by this serializer.- Parameters:
type- the value type.- Returns:
trueif the value type can be serialized;falseotherwise.
-
getTargetType
Return the serializer target type.- Returns:
- the serializer target type.
-