Class GenericToStringSerializer<T>

java.lang.Object
org.springframework.data.redis.serializer.GenericToStringSerializer<T>
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, RedisSerializer<T>

public class GenericToStringSerializer<T> extends Object implements RedisSerializer<T>, org.springframework.beans.factory.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 Details

    • GenericToStringSerializer

      public GenericToStringSerializer(Class<T> type)
    • GenericToStringSerializer

      public GenericToStringSerializer(Class<T> type, Charset charset)
  • Method Details

    • setConversionService

      public void setConversionService(org.springframework.core.convert.ConversionService conversionService)
      Set the ConversionService to be used.
      Parameters:
      conversionService - the conversion service to be used, must not be null.
    • setTypeConverter

      public void setTypeConverter(org.springframework.beans.TypeConverter typeConverter)
      Set the TypeConverter to be used.
      Parameters:
      typeConverter - the conversion service to be used, must not be null.
    • serialize

      public byte[] serialize(@Nullable T value)
      Description copied from interface: RedisSerializer
      Serialize the given object to binary data.
      Specified by:
      serialize in interface RedisSerializer<T>
      Parameters:
      value - object to serialize. Can be null.
      Returns:
      the equivalent binary data. Can be null.
    • deserialize

      public T deserialize(@Nullable byte[] bytes)
      Description copied from interface: RedisSerializer
      Deserialize an object from the given binary data.
      Specified by:
      deserialize in interface RedisSerializer<T>
      Parameters:
      bytes - object binary representation. Can be null.
      Returns:
      the equivalent object instance. Can be null.
    • setBeanFactory

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Throws:
      org.springframework.beans.BeansException