1
1
import 'reflect-metadata' ;
2
- import { IDecoratorMetaData } from './' ;
3
2
/**
4
3
* provide interface to indicate the object is allowed to be traversed
5
4
*
@@ -8,17 +7,30 @@ import { IDecoratorMetaData } from './';
8
7
export interface IGenericObject {
9
8
[ key : string ] : any ;
10
9
}
10
+ /**
11
+ * When custom mapping of a property is required.
12
+ *
13
+ * @interface
14
+ */
15
+ export interface ICustomConverter {
16
+ fromJson ( data : any ) : any ;
17
+ toJson ( data : any ) : any ;
18
+ }
11
19
/**
12
20
* IDecoratorMetaData<T>
13
21
* DecoratorConstraint
14
22
*
15
23
* @interface
24
+ * @property {ICustomConverter } customConverter, will be used for mapping the property, if specified
25
+ * @property {boolean } excludeToJson, will exclude the property for serialization, if true
16
26
*/
17
27
export interface IDecoratorMetaData < T > {
18
28
name ?: string ;
19
29
clazz ?: {
20
30
new ( ) : T ;
21
31
} ;
32
+ customConverter ?: ICustomConverter ;
33
+ excludeToJson ?: boolean ;
22
34
}
23
35
/**
24
36
* JsonProperty
@@ -40,3 +52,11 @@ export declare function JsonProperty<T>(metadata?: IDecoratorMetaData<T> | strin
40
52
export declare function deserialize < T extends IGenericObject > ( Clazz : {
41
53
new ( ) : T ;
42
54
} , json : IGenericObject ) : T ;
55
+ /**
56
+ * Serialize: Creates a ready-for-json-serialization object from the provided model instance.
57
+ * Only @JsonProperty decorated properties in the model instance are processed.
58
+ *
59
+ * @param instance an instance of a model class
60
+ * @returns {any } an object ready to be serialized to JSON
61
+ */
62
+ export declare function serialize ( instance : any ) : any ;
0 commit comments