1
- import { Constants , getJsonIgnoreDecorator , getJsonPropertyDecorator , getPropertyDecorator } from './ReflectHelper' ;
1
+ import {
2
+ Constants ,
3
+ getJsonIgnoreDecorator ,
4
+ getJsonPropertyDecorator ,
5
+ getPropertyDecorator ,
6
+ } from "./ReflectHelper" ;
2
7
3
8
/**
4
9
* Decorator names
5
10
*/
6
- export const JSON_PROPERTY_DECORATOR_NAME = ' JsonProperty' ;
11
+ export const JSON_PROPERTY_DECORATOR_NAME = " JsonProperty" ;
7
12
// const JSON_IGNORE_DECORATOR_NAME = 'JsonIgnore';
8
13
9
14
/**
10
15
* Decorator metadata definition for JsonProperty
11
16
*/
12
17
export interface JsonPropertyDecoratorMetadata {
13
- name ?: string ; // name of the JSON property to map
14
- required ?: boolean ; // is this field required in the JSON object that is being deserialized
15
- access ?: AccessType ; // is this serializable and de-serializable
16
- type ?: any ; // the type of Object that should be assigned to this property
17
- serializer ?: any ; // Serializer for the type
18
- deserializer ?: any ; // deserializer for the type
18
+ name ?: string ; // name of the JSON property to map
19
+ required ?: boolean ; // is this field required in the JSON object that is being deserialized
20
+ access ?: AccessType ; // is this serializable and de-serializable
21
+ type ?: any ; // the type of Object that should be assigned to this property
22
+ serializer ?: any ; // Serializer for the type
23
+ deserializer ?: any ; // deserializer for the type
19
24
}
20
25
21
26
export enum AccessType {
22
- READ_ONLY , WRITE_ONLY , BOTH
27
+ READ_ONLY ,
28
+ WRITE_ONLY ,
29
+ BOTH ,
23
30
}
24
31
25
32
export interface Serializer {
26
- serialize ( value : any ) : any ;
33
+ serialize ( value : any ) : any ;
27
34
}
28
35
29
36
export interface Deserializer {
30
- deserialize ( value : any ) : any ;
37
+ deserialize ( value : any ) : any ;
31
38
}
32
39
33
40
/**
34
41
* JsonProperty Decorator function.
35
42
*/
36
- export const JsonProperty = ( metadata ?: JsonPropertyDecoratorMetadata | string ) : any => {
37
- if ( typeof metadata === 'string' ) {
38
- return getJsonPropertyDecorator ( { name : metadata as string , required : false , access : AccessType . BOTH } ) ;
39
- } else {
40
- return getJsonPropertyDecorator ( metadata ) ;
41
- }
43
+ export const JsonProperty = (
44
+ metadata ?: JsonPropertyDecoratorMetadata | string
45
+ ) : any => {
46
+ if ( typeof metadata === "string" ) {
47
+ return getJsonPropertyDecorator ( {
48
+ name : metadata as string ,
49
+ required : false ,
50
+ access : AccessType . BOTH ,
51
+ } ) ;
52
+ } else {
53
+ return getJsonPropertyDecorator ( metadata ) ;
54
+ }
42
55
} ;
43
56
44
57
/**
@@ -50,31 +63,31 @@ export const JsonProperty = (metadata?: JsonPropertyDecoratorMetadata | string):
50
63
* @returns
51
64
*/
52
65
export const CacheKey = ( key : string ) : Function => {
53
- return ( f : Function ) => {
54
- const functionName = ' getJsonObjectMapperCacheKey' ;
55
- const functionImpl = new Function ( `return '${ key } ';` ) ;
56
- f [ functionName ] = functionImpl ;
57
- } ;
66
+ return ( f : Function ) => {
67
+ const functionName = " getJsonObjectMapperCacheKey" ;
68
+ const functionImpl = new Function ( `return '${ key } ';` ) ;
69
+ f [ functionName ] = functionImpl ;
70
+ } ;
58
71
} ;
59
72
60
73
/**
61
74
* JsonIgnore Decorator function.
62
75
*/
63
76
export const JsonIgnore = ( ) : Function => {
64
- return getJsonIgnoreDecorator ( ) ;
77
+ return getJsonIgnoreDecorator ( ) ;
65
78
} ;
66
79
67
80
/**
68
81
* Json convertion error type.
69
82
*/
70
83
export class JsonConverstionError {
71
- private json : string ;
72
- private message : string ;
73
- private stack : string ;
84
+ private json : string ;
85
+ private message : string ;
86
+ private stack : string ;
74
87
75
- constructor ( message : string , json : string ) {
76
- this . json = json ;
77
- this . message = message ;
78
- this . stack = ( new Error ( ) ) . stack ;
79
- }
88
+ constructor ( message : string , json : string ) {
89
+ this . json = json ;
90
+ this . message = message ;
91
+ this . stack = new Error ( ) . stack ;
92
+ }
80
93
}
0 commit comments