Interface ValueSerializer<T>

  • All Superinterfaces:
    java.io.Serializable

    @Stable
    public interface ValueSerializer<T>
    extends java.io.Serializable
    A serializer of values with specified scheme.
    • Method Detail

      • deserialize

        java.util.Optional<T> deserialize​(byte[] input)
        Deserialize the bytes to materialized typed message. If the deserialization fails the returned value is empty.
        Parameters:
        input - the serialized data
        Returns:
        optional deserialized output
      • serialize

        byte[] serialize​(T value)
        Serialize value to bytes.
        Parameters:
        value - the deserialized value
        Returns:
        serialized bytes
      • getDefault

        T getDefault()
        Retrieve a default value for the type.
        Returns:
        default value of the type
      • isUsable

        default boolean isUsable()
        Check if given serializer can be used without exceptions.
        Returns:
        true if serializer is usable
      • isValid

        default boolean isValid​(byte[] input)
        Check if given input is valid by trying to parse it.
        Parameters:
        input - serialized data
        Returns:
        true if this is valid byte representation
      • asJsonValue

        default java.lang.String asJsonValue​(T value)
        Convert given value to JSON representation (including quotation).
        Parameters:
        value - the value to encode
        Returns:
        the JSON string
      • fromJsonValue

        default T fromJsonValue​(java.lang.String json)
        Convert given JSON string to parsed object.
        Parameters:
        json - the JSON representation
        Returns:
        parsed object
      • getLogString

        default java.lang.String getLogString​(T value)
        Create a (preferably single line) String representation of the value suitable for logging.
        Parameters:
        value - the value to log Convert value to String suitable for logging.
        Returns:
        a String representation suitable for logging