Class OxmSerializer

java.lang.Object
org.springframework.data.redis.serializer.OxmSerializer
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, RedisSerializer<Object>

public class OxmSerializer extends Object implements org.springframework.beans.factory.InitializingBean, RedisSerializer<Object>
Serializer adapter on top of Spring's O/X Mapping. Delegates serialization/deserialization to OXM Marshaller and Unmarshaller. Note: null objects are serialized as empty arrays and vice versa.
Author:
Costin Leau, Mark Paluch
  • Constructor Details

    • OxmSerializer

      public OxmSerializer()
      Creates a new, uninitialized OxmSerializer. Requires setMarshaller(Marshaller) and setUnmarshaller(Unmarshaller) to be set before this serializer can be used.
    • OxmSerializer

      public OxmSerializer(org.springframework.oxm.Marshaller marshaller, org.springframework.oxm.Unmarshaller unmarshaller)
      Creates a new OxmSerializer given Marshaller and Unmarshaller.
      Parameters:
      marshaller - must not be null.
      unmarshaller - must not be null.
  • Method Details

    • setMarshaller

      public void setMarshaller(org.springframework.oxm.Marshaller marshaller)
      Parameters:
      marshaller - The marshaller to set.
    • setUnmarshaller

      public void setUnmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)
      Parameters:
      unmarshaller - The unmarshaller to set.
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • serialize

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

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