Class GenericToStringSerializer<T>
java.lang.Object
org.springframework.data.redis.serializer.GenericToStringSerializer<T>
- All Implemented Interfaces:
Aware,BeanFactoryAware,RedisSerializer<T>
public class GenericToStringSerializer<T>
extends Object
implements RedisSerializer<T>, BeanFactoryAware
Generic String to byte[] (and back) serializer. Relies on the Spring
ConversionService to transform objects
into String and vice versa. The Strings are convert into bytes and vice-versa using the specified charset (by default
UTF-8). Note: The conversion service initialization happens automatically if the class is defined as a Spring
bean. Note: Does not handle nulls in any special way delegating everything to the container.- Author:
- Costin Leau, Christoph Strobl, Mark Paluch
-
Constructor Summary
ConstructorsConstructorDescriptionGenericToStringSerializer(Class<T> type) GenericToStringSerializer(Class<T> type, Charset charset) -
Method Summary
Modifier and TypeMethodDescriptiondeserialize(byte[] bytes) Deserialize an object from the given binary data.byte[]Serialize the given object to binary data.voidsetBeanFactory(BeanFactory beanFactory) voidsetConversionService(ConversionService conversionService) Set theConversionServiceto be used.voidsetTypeConverter(TypeConverter typeConverter) Set theTypeConverterto be used.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
-
Constructor Details
-
GenericToStringSerializer
-
GenericToStringSerializer
-
-
Method Details
-
setConversionService
Set theConversionServiceto be used.- Parameters:
conversionService- the conversion service to be used, must not be null.
-
setTypeConverter
Set theTypeConverterto be used.- Parameters:
typeConverter- the conversion service to be used, must not be null.
-
serialize
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 null.
-
deserialize
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.
-
setBeanFactory
- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Throws:
BeansException
-