Interface Codec

  • All Known Implementing Classes:
    Codecs.ByteArrayCodec, Codecs.DoubleCodec, Codecs.IntegerCodec, Codecs.JsonCodec, Codecs.StringCodec

    public interface Codec
    Redis codec interface.

    The Redis data source uses this interface to serialize and deserialize data to and from Redis. A set of default codecs are provided for Strings, Integers, Doubles and Byte arrays. For custom types, either there is a specific implementation of this interface exposed as CDI (Application Scoped) bean, or JSON is used.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean canHandle​(Type clazz)
      Checks if the current codec can handle the serialization and deserialization of object from the given type.
      Object decode​(byte[] item)
      Decodes the given bytes to an object.
      byte[] encode​(Object item)
      Encodes the given object.
    • Method Detail

      • canHandle

        boolean canHandle​(Type clazz)
        Checks if the current codec can handle the serialization and deserialization of object from the given type.
        Parameters:
        clazz - the type, cannot be null
        Returns:
        true if the codec can handle the type, false otherwise
      • encode

        byte[] encode​(Object item)
        Encodes the given object. The type of the given object matches the type used to call the canHandle(Type) method.
        Parameters:
        item - the item
        Returns:
        the encoded content
      • decode

        Object decode​(byte[] item)
        Decodes the given bytes to an object. The codec must return an instance of the type used to call the canHandle(Type) method.
        Parameters:
        item - the bytes
        Returns:
        the object