-
Notifications
You must be signed in to change notification settings - Fork 55
/
index.d.ts
62 lines (62 loc) · 1.81 KB
/
index.d.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import 'reflect-metadata';
/**
* provide interface to indicate the object is allowed to be traversed
*
* @interface
*/
export interface IGenericObject {
[key: string]: any;
}
/**
* When custom mapping of a property is required.
*
* @interface
*/
export interface ICustomConverter {
fromJson(data: any): any;
toJson(data: any): any;
}
/**
* IDecoratorMetaData<T>
* DecoratorConstraint
*
* @interface
* @property {ICustomConverter} customConverter, will be used for mapping the property, if specified
* @property {boolean} excludeToJson, will exclude the property for serialization, if true
*/
export interface IDecoratorMetaData<T> {
name?: string;
clazz?: {
new (): T;
};
customConverter?: ICustomConverter;
excludeToJson?: boolean;
}
/**
* JsonProperty
*
* @function
* @property {IDecoratorMetaData<T>|string} metadata, encapsulate it to DecoratorMetaData for standard use
* @return {(target:Object, targetKey:string | symbol)=> void} decorator function
*/
export declare function JsonProperty<T>(metadata?: IDecoratorMetaData<T> | string): (target: Object, targetKey: string | symbol) => void;
/**
* deserialize
*
* @function
* @param {{new():T}} clazz, class type which is going to initialize and hold a mapping json
* @param {Object} json, input json object which to be mapped
*
* @return {T} return mapped object
*/
export declare function deserialize<T extends IGenericObject>(Clazz: {
new (): T;
}, json: IGenericObject): T;
/**
* Serialize: Creates a ready-for-json-serialization object from the provided model instance.
* Only @JsonProperty decorated properties in the model instance are processed.
*
* @param instance an instance of a model class
* @returns {any} an object ready to be serialized to JSON
*/
export declare function serialize(instance: any): any;