Home Manual Reference Source Repository
import {SerializerContainer} from 'ug-layout/serialization/SerializerContainer'
public class | source

SerializerContainer

A container for running and determining serializers.

Example:


const container = new SerializerContainer();

class MyClass {}

const mySerializer = new GenericSerializer('MyClass', MyClass);

container.registerSerializer(MyClass, mySerializer);
container.serialize(new MyClass()); // => { name: 'MyClass' }
container.deserialize({ name: 'MyClass' }); // => MyClass

Constructor Summary

Public Constructor
public

Creates an instance of SerializerContainer.

Method Summary

Public Methods
public

deserialize(serialized: S): R

Deserializes a serialized node using the registered serializer for that node type.

public

deserializeList(serialized: *): *

public

isExcluded(instance: *): boolean

public

registerClass(name: string, _Class: Type<any>)

Registers a class that can be identified by a string representation.

public

registerClasses(classes: {[key: string]})

Registers multiple classes that can be identified by a string representation.

public

registerSerializer(_Class: Type<any>, serializer: BaseSerializer | Type<BaseSerializer>, options: {skipRegister?: boolean})

Registers a serializer with the container.

public

resolve(token: *): T | null

Resolves a token with this containers injector.

public

resolveClass(name: string): Type<any> | null

Resolves a string to a registered class.

public

resolveClassString(_Class: Type<any>): string | null

Resolves a class to it's registered string representation.

public

resolveFromClass(_Class: Type<any>): BaseSerializer | null

Resolves a serializer from a class.

public

resolveFromInstance(instance: Renderable & Constructable<any>): BaseSerializer | null

Resolves a serializer from an instance of a registered class.

public

resolveFromSerialized(node: Serialized): BaseSerializer | null

Resolves a serializer from a serialized node.

public

serialize(instance: R): S

Serializes a class instance using the registered serializer for that class.

public

serializeList(instances: *): *

Public Constructors

public constructor(config: SerializerContainerConfig) source

Creates an instance of SerializerContainer.

Params:

NameTypeAttributeDescription
config SerializerContainerConfig
  • optional
  • default: {}

Public Methods

public deserialize(serialized: S): R source

Deserializes a serialized node using the registered serializer for that node type.

Params:

NameTypeAttributeDescription
serialized S

Return:

R

The renderable argument.

public deserializeList(serialized: *): * source

Params:

NameTypeAttributeDescription
serialized *

Return:

*

public isExcluded(instance: *): boolean source

Params:

NameTypeAttributeDescription
instance *

Return:

boolean

public registerClass(name: string, _Class: Type<any>) source

Registers a class that can be identified by a string representation.

Params:

NameTypeAttributeDescription
name string
_Class Type<any>

public registerClasses(classes: {[key: string]}) source

Registers multiple classes that can be identified by a string representation.

Params:

NameTypeAttributeDescription
classes {[key: string]}
  • optional
  • default: {}

public registerSerializer(_Class: Type<any>, serializer: BaseSerializer | Type<BaseSerializer>, options: {skipRegister?: boolean}) source

Registers a serializer with the container.

Params:

NameTypeAttributeDescription
_Class Type<any>
serializer BaseSerializer | Type<BaseSerializer>
options {skipRegister?: boolean}
  • optional
  • default: {}

public resolve(token: *): T | null source

Resolves a token with this containers injector.

Params:

NameTypeAttributeDescription
token *

Return:

T | null

public resolveClass(name: string): Type<any> | null source

Resolves a string to a registered class.

Params:

NameTypeAttributeDescription
name string

Return:

Type<any> | null

public resolveClassString(_Class: Type<any>): string | null source

Resolves a class to it's registered string representation.

Params:

NameTypeAttributeDescription
_Class Type<any>

Return:

string | null

public resolveFromClass(_Class: Type<any>): BaseSerializer | null source

Resolves a serializer from a class.

Params:

NameTypeAttributeDescription
_Class Type<any>

Return:

BaseSerializer | null

public resolveFromInstance(instance: Renderable & Constructable<any>): BaseSerializer | null source

Resolves a serializer from an instance of a registered class.

Params:

NameTypeAttributeDescription
instance Renderable & Constructable<any>

Return:

BaseSerializer | null

public resolveFromSerialized(node: Serialized): BaseSerializer | null source

Resolves a serializer from a serialized node.

Params:

NameTypeAttributeDescription
node Serialized

Return:

BaseSerializer | null

public serialize(instance: R): S source

Serializes a class instance using the registered serializer for that class.

Params:

NameTypeAttributeDescription
instance R

Return:

S

The serialized node.

public serializeList(instances: *): * source

Params:

NameTypeAttributeDescription
instances *

Return:

*