API reference / @node-ts/bus-core / Serializer
Interface: Serializer
Defined in: packages/bus-core/src/serialization/serializer.ts:10
A serializer that's use to serialize/deserialize objects as they leave and enter the application boundary.
A serializer holds no state of its own bus, so one instance can be shared by several buses. Each bus passes the message types it was configured with, using withMessageTypes(), to every call that restores an object.
Methods
deserialize()
deserialize<T>(
val,
classType,
messageTypes?
): T;Defined in: packages/bus-core/src/serialization/serializer.ts:26
Reads an object written by serialize
Type Parameters
| Type Parameter |
|---|
T extends object |
Parameters
| Parameter | Type | Description |
|---|---|---|
val | string | the serialized object |
classType | ClassConstructor<T> | the class the top-level object is created from |
messageTypes? | MessageTypes | the message types of the bus that's reading the object, which say how to restore its nested values |
Returns
T
the object
serialize()
serialize<T>(obj): string;Defined in: packages/bus-core/src/serialization/serializer.ts:16
Writes an object as a string
Type Parameters
| Type Parameter |
|---|
T extends object |
Parameters
| Parameter | Type | Description |
|---|---|---|
obj | T | the message or workflow state to write |
Returns
string
the serialized object
toClass()
toClass<T>(
obj,
classConstructor,
messageTypes?
): T;Defined in: packages/bus-core/src/serialization/serializer.ts:47
Converts a plain object, such as one returned by toPlain, back to its class
Type Parameters
| Type Parameter |
|---|
T extends object |
Parameters
| Parameter | Type | Description |
|---|---|---|
obj | object | the plain object |
classConstructor | ClassConstructor<T> | the class the top-level object is created from |
messageTypes? | MessageTypes | the message types of the bus that's reading the object, which say how to restore its nested values |
Returns
T
the object
toPlain()
toPlain<T>(obj): object;Defined in: packages/bus-core/src/serialization/serializer.ts:37
Converts an object to a plain object that JSON can represent
Type Parameters
| Type Parameter |
|---|
T extends object |
Parameters
| Parameter | Type | Description |
|---|---|---|
obj | T | the message or workflow state to convert |
Returns
object
the plain object