Dynamic module erializer

Index

Variables

Interfaces

Functions

Variables

space: any

The amount of space to use for indentation when writing out JSON.

default

undefined

typeAttribute: string

The name of the attribute that the serializer should use to identify an object's type.

default

type

typeMap: any

Maps type ids to object constructor functions. Keys are type ids and values are functions.

Functions

clone(obj: T, settings?: Object): T

Clone the object.

Parameters

  • obj: T

    The object to clone.

  • settings?: Object optional

Returns

T

The new clone.

deserialize(text: string, settings?: DeserializerOptions): T

Deserialize the JSON.

Parameters

  • text: string

    The JSON string.

  • settings?: DeserializerOptions optional

    Settings can specify a reviver, getTypeId function or getConstructor function.

Returns

T

The deserialized object.

getTypeId(object: any): string

Gets the type id for an object instance, using the configured typeAttribute.

Parameters

  • object: any

    The object to serialize.

Returns

string

The type.

registerType(typeId: string, constructor: () => any): any

Adds a type id/constructor function mampping to the typeMap.

Parameters

  • typeId: string

    The type id.

  • constructor: () => any

    The constructor.

Returns

any

replacer(key: string, value: any): any

The default replacer function used during serialization. By default properties starting with '_' or '$' are removed from the serialized object.

Parameters

  • key: string

    The object key to check.

  • value: any

    The object value to check.

Returns

any

The value to serialize.

reviver(key: string, value: any, getTypeId: (value: any) => string, getConstructor: (string: any) => () => any): any

The default reviver function used during deserialization. By default is detects type properties on objects and uses them to re-construct the correct object using the provided constructor mapping.

Parameters

  • key: string

    The attribute key.

  • value: any

    The object value associated with the key.

  • getTypeId: (value: any) => string

    A custom function used to get the type id from a value.

  • getConstructor: (string: any) => () => any

    A custom function used to get the constructor function associated with a type id.

Returns

any

The value.

serialize(object: any, settings?: string): any

Serializes the object.

Parameters

  • object: any

    The object to serialize.

  • settings?: string optional

Returns

any

The JSON string.

serialize(object: any, settings?: number): any

Serializes the object.

Parameters

  • object: any

    The object to serialize.

  • settings?: number optional

Returns

any

The JSON string.

serialize(object: any, settings?: SerializerOptions): any

Serializes the object.

Parameters

Returns

any

The JSON string.