Serialize TS
Metadata library that created to resolve your pain with all mappers and type-checking of objects after serialization or deserialization.
Don`t use the spread operator for copying of your models because prototypes chain will be lost after it!
Getting started
Instalation
- Add a dependency to your package.json file:
npm install serialize-ts --save
or yarn add serialize-ts
;
- Change a tsconfig.json:
Exmaples
Serialization
Simple model:
;model.id = 12;model.fullName = "Default full name";model.ignoredField =; console.logserializemodel; /*Output -> { server-id: 12, fullName: 'Default full name'}*/ ; console.logdeserializeobj, TestModel; /*Output -> TestModel { id: 12, fullName: 'Default full name'}*/
Nested models:
; ;console.logouterModel; /* Output -> OuterModel { id: 12, nestedModel: NestedModel { firstField: 24, secondField: "Some awesome string!" } }*/ console.logserializeouterModel; /* Output -> { id: 12, nestedModel: { firstField: 24, secondField: "Some awesome string!" } }*/
Arrays:
; ;console.logdeserializedModel;/* Output -> Test { id: 12, arrayOfNumber: [12, 24, 36, 48] }*/
Custom serializers:
If you have some troubles with serialization without serializer decorator definition, you are able to define it with @Serializer(YourCustomModel)
or with some default type like Date or String.
I am waiting for the issues of course!