Class

DeterministicSerializer

DeterministicSerializer(constructoropt)

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

View Source shared/DeterministicSerializer.ts, line 5

Example
const serializer = new DeterministicSerializer<MyModel>();
const json = serializer.serialize(model);
const rebuilt = serializer.deserialize(json);

Methods

# deserialize(str) → {M}

Rebuilds a model from a serialization

Parameters:
Name Type Description
str string

View Source shared/DeterministicSerializer.ts, line 96

If it fails to parse the string, or to build the model

Error
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

View Source shared/DeterministicSerializer.ts, line 104

Deterministic JSON representation of the model

string