# 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
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
constructor |
void
|
<optional> |
No public constructor arguments; provided for documentation completeness |
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 |
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 |
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 |
A JSON string containing the serialized model with anchor metadata
string