This repository was archived by the owner on May 4, 2023. It is now read-only.
File tree 4 files changed +58
-0
lines changed
4 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { ListItem } from './support/ListItem' ;
2
+ import { WithType } from './support/WithType' ;
2
3
import { SpecReporter } from 'jasmine-spec-reporter' ;
3
4
// Module
4
5
import { JsonTypescriptService } from './../main/service/JsonTypescriptService' ;
5
6
import { Logger } from './../main/log/Logger' ;
6
7
7
8
// Moment
8
9
import * as moment from 'moment' ;
10
+ import { Parent } from './support/Parent' ;
9
11
10
12
// Setup...
11
13
const log = Logger . getInstance ( ) ;
@@ -87,3 +89,29 @@ describe('Deserialize null values', () => {
87
89
expect ( deserialized . lorem ) . toBeNull ( ) ;
88
90
} ) ;
89
91
} ) ;
92
+
93
+ describe ( 'Deserializing Model objects' , ( ) => {
94
+ const parent : any = {
95
+ child : {
96
+ name : 'Kind' ,
97
+ } ,
98
+ } ;
99
+
100
+ const deserialized = jsog . deserializeObject ( parent , Parent ) ;
101
+
102
+ it ( 'should instantiate child' , ( ) => {
103
+ expect ( deserialized . child . getName ( ) ) . toBeDefined ( ) ;
104
+ } ) ;
105
+ } ) ;
106
+
107
+ describe ( 'Deserializing Annotated String Types' , ( ) => {
108
+ const withType : WithType = {
109
+ dtype : 'one' ,
110
+ } ;
111
+
112
+ const deserialized = jsog . deserializeObject ( withType , WithType ) ;
113
+
114
+ it ( 'should work' , ( ) => {
115
+ expect ( deserialized ) . toEqual ( withType ) ;
116
+ } ) ;
117
+ } ) ;
Original file line number Diff line number Diff line change
1
+ export class Child {
2
+ public name : string ;
3
+
4
+ public getName ( ) : string {
5
+ return this . name ;
6
+ }
7
+ }
Original file line number Diff line number Diff line change
1
+ import { Child } from './Child' ;
2
+ import { JsonProperty } from '../../main/decorators/JsonProperty' ;
3
+
4
+ export class Parent {
5
+
6
+ @JsonProperty ( )
7
+ public child : Child ;
8
+
9
+ constructor ( data ?: Parent ) {
10
+
11
+ if ( ! data ) {
12
+ return ;
13
+ }
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ import { JsonProperty } from '../../main/decorators/JsonProperty' ;
2
+
3
+ type StringType = 'one' | 'other' ;
4
+
5
+ export class WithType {
6
+ @JsonProperty ( )
7
+ public dtype : StringType ;
8
+ }
You can’t perform that action at this time.
0 commit comments