1
0

Custom Serializer updates

This commit is contained in:
2020-07-17 14:08:02 -04:00
parent b2769c8841
commit 6c9ccd7f82
2 changed files with 35 additions and 4 deletions

View File

@@ -0,0 +1,30 @@
import 'reflect-metadata';
import { Serde } from "src/serde";
import { Exclude } from 'src/decorators';
class NestedModel extends Serde<NestedModel> {
name: string;
@Exclude() excluded: boolean;
}
class ParentModel extends Serde<ParentModel> {
name: string;
nested: NestedModel;
@Exclude() excluded: boolean;
}
describe('Custom serlializer', () => {
it('should run custom seiralizer once', () => {
const testModel = new ParentModel().deserialize({
name: 'parent model',
excluded: true,
nested: new NestedModel().deserialize({
name: 'nested model',
excluded: true
})
});
const serializedModel = testModel.serialize();
expect(serializedModel).toEqual({ name: 'parent model', nested: { name: 'nested model' } });
});
});