Interface SerializerAdapter

  • All Known Implementing Classes:
    JacksonAdapter

    public interface SerializerAdapter
    An interface defining the behaviors of a serializer.
    • Method Detail

      • serialize

        String serialize​(Object object,
                         SerializerEncoding encoding)
                  throws IOException
        Serializes an object into a string.
        Parameters:
        object - The object to serialize.
        encoding - The serialization encoding.
        Returns:
        The object serialized as a string using the specified encoding. If the object is null null is returned.
        Throws:
        IOException - If an IO exception was thrown during serialization.
      • serializeToBytes

        default byte[] serializeToBytes​(Object object,
                                        SerializerEncoding encoding)
                                 throws IOException
        Serializes an object into a byte array.
        Parameters:
        object - The object to serialize.
        encoding - The serialization encoding.
        Returns:
        The object serialized as a byte array.
        Throws:
        IOException - If an IO exception was thrown during serialization.
      • serialize

        default void serialize​(Object object,
                               SerializerEncoding encoding,
                               OutputStream outputStream)
                        throws IOException
        Serializes an object and writes its output into an OutputStream.
        Parameters:
        object - The object to serialize.
        encoding - The serialization encoding.
        outputStream - The OutputStream where the serialized object will be written.
        Throws:
        IOException - If an IO exception was thrown during serialization.
      • serializeRaw

        String serializeRaw​(Object object)
        Serializes an object into a raw string, leading and trailing quotes will be trimmed.
        Parameters:
        object - The object to serialize.
        Returns:
        The object serialized as a string. If the object is null null is returned.
      • serializeList

        String serializeList​(List<?> list,
                             CollectionFormat format)
        Serializes a list into a string with the delimiter specified with the Swagger collection format joining each individual serialized items in the list.
        Parameters:
        list - The list to serialize.
        format - The collection joining format.
        Returns:
        The list serialized as a joined string.
      • serializeIterable

        default String serializeIterable​(Iterable<?> iterable,
                                         CollectionFormat format)
        Serializes an iterable into a string with the delimiter specified with the Swagger collection format joining each individual serialized items in the list.
        Parameters:
        iterable - The iterable to serialize.
        format - The collection joining format.
        Returns:
        The iterable serialized as a joined string.
      • deserialize

        <T> T deserialize​(String value,
                          Type type,
                          SerializerEncoding encoding)
                   throws IOException
        Deserializes a string into an object.
        Type Parameters:
        T - The type of the deserialized object.
        Parameters:
        value - The string to deserialize.
        type - The type of the deserialized object.
        encoding - The deserialization encoding.
        Returns:
        The string deserialized into an object.
        Throws:
        IOException - If an IO exception was thrown during deserialization.
      • deserialize

        default <T> T deserialize​(byte[] bytes,
                                  Type type,
                                  SerializerEncoding encoding)
                           throws IOException
        Deserializes a byte array into an object.
        Type Parameters:
        T - The type of the deserialized object.
        Parameters:
        bytes - The byte array to deserialize.
        type - The type of the deserialized object.
        encoding - The deserialization encoding.
        Returns:
        The string deserialized into an object.
        Throws:
        IOException - If an IO exception was thrown during serialization.
      • deserialize

        default <T> T deserialize​(InputStream inputStream,
                                  Type type,
                                  SerializerEncoding encoding)
                           throws IOException
        Deserializes a stream into an object.
        Type Parameters:
        T - The type of the deserialized object.
        Parameters:
        inputStream - The InputStream to deserialize.
        type - The type of the deserialized object.
        encoding - The deserialization encoding.
        Returns:
        The stream deserialized into an object.
        Throws:
        IOException - If an IO exception was thrown during serialization.
      • deserialize

        <T> T deserialize​(HttpHeaders headers,
                          Type type)
                   throws IOException
        Deserialize the provided headers returned from a REST API to an entity instance declared as the model to hold 'Matching' headers.

        'Matching' headers are the REST API returned headers those with:

        1. header names same as name of a properties in the entity.
        2. header names start with value of HeaderCollection annotation applied to the properties in the entity.
        When needed, the 'header entity' types must be declared as first generic argument of ResponseBase returned by java proxy method corresponding to the REST API. e.g. Mono<RestResponseBase<FooMetadataHeaders, Void>> getMetadata(args); class FooMetadataHeaders { String name; {@literal @}HeaderCollection("header-collection-prefix-") Map<String,String> headerCollection; } in the case of above example, this method produces an instance of FooMetadataHeaders from provided headers.
        Type Parameters:
        T - the type of the deserialized object
        Parameters:
        headers - the REST API returned headers
        type - the type to deserialize
        Returns:
        instance of header entity type created based on provided headers, if header entity model does not not exists then return null
        Throws:
        IOException - If an I/O error occurs