Skip to content

@gala-chain/apiAPI


API > SerializeIf

Function: SerializeIf()

SerializeIf(condition, transformOptions?): PropertyDecorator

Parameters

condition: (obj) => boolean

Function that receives the object and returns true if the property should be included

transformOptions?: TransformOptions

Optional class-transformer options

Returns

Description

Decorator that conditionally includes/excludes a property during serialization/deserialization based on a condition function that evaluates other properties of the object.

Example

class MyClass {
  @SerializeIf(o => !o.publicKeys || o.publicKeys.length === 0)
  public publicKey?: string;

  @SerializeIf(o => !o.publicKey)
  public publicKeys?: string[];
}

Source

chain-api/src/validators/decorators.ts:255