-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathapp.ts
35 lines (30 loc) · 831 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import 'es6-shim';
import 'reflect-metadata';
import { classToPlain, plainToClass } from '../../src/index';
import { Photo } from './Photo';
// check deserialization
let photoJson = {
id: '1',
filename: 'myphoto.jpg',
description: 'about my photo',
tags: ['me', 'iam'],
albums: [
{
id: '1',
name: 'My life',
},
{
id: '2',
name: 'My young years',
},
],
};
let photo = plainToClass(Photo, photoJson);
console.log('deserialized object: ', photo);
console.log('-----------------------------');
console.log('Trying to find album: ', photo.albums.findByName('My life'));
console.log('-----------------------------');
// now check serialization
let newPhotoJson = classToPlain(photo);
console.log('serialized object: ', newPhotoJson);
console.log('-----------------------------');