Constructor
# new DeterministicSerializer(constructoropt)
Ensures stable, deterministic JSON output by sorting object keys recursively before stringification, which is important for Fabric endorsement and hashing. Extends JSONSerializer to plug into existing Decaf model serialization flow.
Deterministic JSON serializer for Fabric models
sequenceDiagram
participant Caller
participant DS as DeterministicSerializer
Caller->>DS: serialize(model)
DS->>DS: preSerialize(model)
DS->>DS: sort-keys-recursive
DS->>DS: json-stringify-deterministic
DS-->>Caller: string
Caller->>DS: deserialize(string)
DS-->>Caller: model
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
constructor |
void
|
<optional> |
No public constructor arguments |
Example
const serializer = new DeterministicSerializer<MyModel>();
const json = serializer.serialize(model);
const rebuilt = serializer.deserialize(json);
Methods
# deserialize(str) → {M}
Delegates to the base JSONSerializer implementation to rebuild the model
Deserialize a JSON string into a model instance
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string
|
The JSON string to deserialize |
The reconstructed model instance
M
# serialize(model) → {string}
Prepares the model with preSerialize, sorts keys recursively, and stringifies deterministically for stable ordering
Serialize a model into a deterministic JSON string
Parameters:
| Name | Type | Description |
|---|---|---|
model |
M
|
The model instance to serialize |
Deterministic JSON representation of the model
string