Serializer class

Used to map raw response objects to final shapes. Helps packing and unpacking Dates and other encoded types that are not intrinsic to JSON. Also allows pulling values from headers, as well as inserting default values and constants.

Constructors

Serializer({[key: string]: any}, boolean)

Properties

isXML

Whether the contents are XML or not.

modelMappers

The provided model mapper.

Methods

deserialize(Mapper, unknown, string, SerializerOptions)

Deserialize the given object based on its metadata defined in the mapper.

serialize(Mapper, unknown, string, SerializerOptions)

Serialize the given object based on its metadata defined in the mapper.

validateConstraints(Mapper, unknown, string)

Validates constraints, if any. This function will throw if the provided value does not respect those constraints.

Constructor Details

Serializer({[key: string]: any}, boolean)

new Serializer(modelMappers?: {[key: string]: any}, isXML?: boolean)

Parameters

modelMappers

{[key: string]: any}

The provided model mapper.

isXML

boolean

Whether the contents are XML or not.

Property Details

isXML

Whether the contents are XML or not.

isXML?: boolean

Property Value

boolean

modelMappers

The provided model mapper.

modelMappers: {[key: string]: any}

Property Value

{[key: string]: any}

Method Details

deserialize(Mapper, unknown, string, SerializerOptions)

Deserialize the given object based on its metadata defined in the mapper.

function deserialize(mapper: Mapper, responseBody: unknown, objectName: string, options?: SerializerOptions): any

Parameters

mapper
Mapper

The mapper which defines the metadata of the serializable object.

responseBody

unknown

A valid Javascript entity to be deserialized.

objectName

string

Name of the deserialized object.

options
SerializerOptions

Controls behavior of XML parser and builder.

Returns

any

A valid deserialized Javascript object.

serialize(Mapper, unknown, string, SerializerOptions)

Serialize the given object based on its metadata defined in the mapper.

function serialize(mapper: Mapper, object: unknown, objectName?: string, options?: SerializerOptions): any

Parameters

mapper
Mapper

The mapper which defines the metadata of the serializable object.

object

unknown

A valid Javascript object to be serialized.

objectName

string

Name of the serialized object.

options
SerializerOptions

additional options to deserialization.

Returns

any

A valid serialized Javascript object.

validateConstraints(Mapper, unknown, string)

Warning

This API is now deprecated.

Removing the constraints validation on client side.

Validates constraints, if any. This function will throw if the provided value does not respect those constraints.

function validateConstraints(mapper: Mapper, value: unknown, objectName: string)

Parameters

mapper
Mapper

The definition of data models.

value

unknown

The value.

objectName

string

Name of the object. Used in the error messages.