-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
40 lines (32 loc) · 1.14 KB
/
main.ts
File metadata and controls
40 lines (32 loc) · 1.14 KB
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
36
37
38
39
40
import 'reflect-metadata';
import { TypedJSON, jsonObject, jsonMember } from 'typedjson';
const onDeserializedMethodName = "onDeserializedTest"
@jsonObject({
onDeserialized: onDeserializedMethodName
})
class TargetClass {
constructor () {}
@jsonMember public testProp1?: string;
@jsonMember public testProp2?: number;
public onDeserializedTest(): void {
console.log('Deserializer was called!');
}
}
function run(json: string): void {
// This check mimics what TypedJSON is doing (the issue)
let manualInstance = new TargetClass();
var deserializerType = typeof (manualInstance.constructor as any)[onDeserializedMethodName];
if (deserializerType === 'function') {
(manualInstance.constructor as any)[onDeserializedMethodName]();
} else {
console.log('Failed to detect type of function', deserializerType);
}
// The parse call below will fail to execute onDeserialized as expected
let serializer = new TypedJSON(TargetClass);
let targetClass = serializer.parse(json);
console.log('targetClass', targetClass);
}
run(`{
"testProp1": "value 1",
"testProp2": 2
}`);