SerializerAdapter Interface

public interface SerializerAdapter

An interface defining the behaviors of a serializer.

Method Summary

Modifier and Type Method and Description
default T deserialize(byte[] bytes, Type type, SerializerEncoding encoding)

Deserializes a byte array into an object.

abstract T deserialize(HttpHeaders headers, Type type)

Deserialize the provided headers returned from a REST API to an entity instance declared as the model to hold 'Matching' headers.

default T deserialize(InputStream inputStream, Type type, SerializerEncoding encoding)

Deserializes a stream into an object.

abstract T deserialize(String value, Type type, SerializerEncoding encoding)

Deserializes a string into an object.

default T deserializeHeader(Header header, Type type)

Deserializes the provided header returned from a REST API to en entity instance declared as the model of the header.

abstract String serialize(Object object, SerializerEncoding encoding)

Serializes an object into a string.

default void serialize(Object object, SerializerEncoding encoding, OutputStream outputStream)

Serializes an object and writes its output into an OutputStream.

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.

abstract 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.

abstract String serializeRaw(Object object)

Serializes an object into a raw string, leading and trailing quotes will be trimmed.

default byte[] serializeToBytes(Object object, SerializerEncoding encoding)

Serializes an object into a byte array.

Method Details

deserialize

public default T deserialize(byte[] bytes, Type type, SerializerEncoding encoding)

Deserializes a byte array into an 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

public abstract T deserialize(HttpHeaders headers, Type type)

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<H,T> returned by java proxy method corresponding to the REST API. e.g. Mono> getMetadata(args); class FooMetadataHeaders { String name; {@literal @}HeaderCollection("header-collection-prefix-") Map headerCollection; } in the case of above example, this method produces an instance of FooMetadataHeaders from provided headers.

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 exist then return null

Throws:

IOException

- If an I/O error occurs

deserialize

public default T deserialize(InputStream inputStream, Type type, SerializerEncoding encoding)

Deserializes a stream into an 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

public abstract T deserialize(String value, Type type, SerializerEncoding encoding)

Deserializes a string into an 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.

deserializeHeader

public default T deserializeHeader(Header header, Type type)

Deserializes the provided header returned from a REST API to en entity instance declared as the model of the header.

Parameters:

header - The header.
type - The type that represents the deserialized header.

Returns:

A new instance of the type that represents the deserialized header.

Throws:

IOException

- If an I/O error occurs.

serialize

public abstract String serialize(Object object, SerializerEncoding encoding)

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.

serialize

public default void serialize(Object object, SerializerEncoding encoding, OutputStream outputStream)

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.

serializeIterable

public 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.

serializeList

public abstract 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.

serializeRaw

public abstract 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.

serializeToBytes

public default byte[] serializeToBytes(Object object, SerializerEncoding encoding)

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.

Applies to