Skip to content

Field custom transformer support#4

Open
dianlight wants to merge 5 commits intoastronautlabs:mainfrom
dianlight:transformer_support
Open

Field custom transformer support#4
dianlight wants to merge 5 commits intoastronautlabs:mainfrom
dianlight:transformer_support

Conversation

@dianlight
Copy link

It can be useful to have custom function that transforms the field value after deserialize or before serialize.
Use the transformers option to specify read or/and write function:

class Type2Element extends BaseElement {
    @Field(version, { transformers: {read: v => v/100, write: v => v * 100 })
    version : number;
}

In this example version value 1.20 is the integer 120 on the stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant