Skip to content

Commit e5cf6e7

Browse files
committed
Completed ignoremetadata during deserialization
1 parent cb87e76 commit e5cf6e7

9 files changed

+208256
-30955
lines changed

src/main/DecoratorMetadata.ts

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,57 @@
1-
import { Constants, getJsonIgnoreDecorator, getJsonPropertyDecorator, getPropertyDecorator } from './ReflectHelper';
1+
import {
2+
Constants,
3+
getJsonIgnoreDecorator,
4+
getJsonPropertyDecorator,
5+
getPropertyDecorator,
6+
} from "./ReflectHelper";
27

38
/**
49
* Decorator names
510
*/
6-
export const JSON_PROPERTY_DECORATOR_NAME = 'JsonProperty';
11+
export const JSON_PROPERTY_DECORATOR_NAME = "JsonProperty";
712
// const JSON_IGNORE_DECORATOR_NAME = 'JsonIgnore';
813

914
/**
1015
* Decorator metadata definition for JsonProperty
1116
*/
1217
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
1924
}
2025

2126
export enum AccessType {
22-
READ_ONLY, WRITE_ONLY, BOTH
27+
READ_ONLY,
28+
WRITE_ONLY,
29+
BOTH,
2330
}
2431

2532
export interface Serializer {
26-
serialize(value: any): any;
33+
serialize(value: any): any;
2734
}
2835

2936
export interface Deserializer {
30-
deserialize(value: any): any;
37+
deserialize(value: any): any;
3138
}
3239

3340
/**
3441
* JsonProperty Decorator function.
3542
*/
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+
}
4255
};
4356

4457
/**
@@ -50,31 +63,31 @@ export const JsonProperty = (metadata?: JsonPropertyDecoratorMetadata | string):
5063
* @returns
5164
*/
5265
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+
};
5871
};
5972

6073
/**
6174
* JsonIgnore Decorator function.
6275
*/
6376
export const JsonIgnore = (): Function => {
64-
return getJsonIgnoreDecorator();
77+
return getJsonIgnoreDecorator();
6578
};
6679

6780
/**
6881
* Json convertion error type.
6982
*/
7083
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;
7487

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+
}
8093
}

0 commit comments

Comments
 (0)