Class

ClientSerializer

ClientSerializer(constructoropt) → {void}

Constructor

# new ClientSerializer(constructoropt) → {void}

Extends the base JSONSerializer to embed model metadata (anchor) required to reconstruct instances on the client, and to safely serialize/deserialize Fabric-bound models.

Client-side JSON serializer for Decaf models targeting Hyperledger Fabric

sequenceDiagram participant App participant Serializer as ClientSerializer participant Model App->>Serializer: serialize(model) Serializer->>Serializer: preSerialize(model) Serializer-->>App: JSON string App->>Serializer: deserialize(json) Serializer->>Serializer: JSON.parse(json) Serializer->>Model: Model.build(parsed, anchor) Model-->>App: instance
Parameters:
Name Type Attributes Description
constructor void <optional>

No public constructor arguments; provided for documentation completeness

View Source shared/ClientSerializer.ts, line 5

void
Example
const serializer = new ClientSerializer<User>();
const json = serializer.serialize(new User({ id: "1", name: "Alice" }));
const user = serializer.deserialize(json);

Methods

# deserialize(str) → {M}

Parses the JSON string, retrieves the embedded model anchor, and uses Model.build to reconstruct the original instance

Rebuilds a model from its JSON serialization

Parameters:
Name Type Description
str string

The JSON string previously produced by serialize

View Source shared/ClientSerializer.ts, line 101

The reconstructed model instance

M

# protected preSerialize(model, modelNameopt) → {Record.<string, any>}

Clones the model and injects the class metadata anchor so it can be reconstructed during deserialization. Falls back to provided table name if metadata is not available.

Prepare a model for JSON serialization embedding class anchor

Parameters:
Name Type Attributes Description
model M

The model instance to serialize

modelName string <optional>

Optional table name to use when metadata cannot be derived

View Source shared/ClientSerializer.ts, line 93

A plain object ready to be JSON.stringify'd

Record.<string, any>

# serialize(model, tableopt) → {string}

Prepares the model via preSerialize, embedding metadata needed for reconstruction, and returns a JSON string representation

Serializes a model to a JSON string

Parameters:
Name Type Attributes Description
model M

The model instance to serialize

table string <optional>

Optional table name to include as anchor when metadata is unavailable

View Source shared/ClientSerializer.ts, line 110

A JSON string containing the serialized model with anchor metadata

string