forked from outfoxx/jackson-js
/
SerializationFeature.ts
140 lines (137 loc) · 5.39 KB
/
SerializationFeature.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* @packageDocumentation
* @module Databind
*/
import {JsonIncludeBaseOptions} from '../@types';
import {CommonFeature, DefaultCommonFeatureValues} from './CommonFeature';
/**
* Interface that defines features to set for {@link ObjectMapper} and {@link JsonStringifier}.
*
* Changes only take effect when done before any serialization calls --
* that is, caller must follow "configure-then-use" pattern.
*/
export interface SerializationFeature extends CommonFeature {
/**
* Feature that define global inclusion rules about which properties of a Class are to be included in serialization.
*
* `null` indicates that no global inclusion rules are defined.
*/
DEFAULT_PROPERTY_INCLUSION?: JsonIncludeBaseOptions | null;
/**
* Feature that determines what happens when a direct self-reference is detected by a Class
* (and no Object Id handling is enabled for it):
* either a {@link JacksonError} is thrown (if true), or reference is normally processed (false).
*/
FAIL_ON_SELF_REFERENCES?: boolean;
/**
* Feature that determines whether `Map` or Object Literal entries are first sorted by key before serialization or not:
* if enabled, additional sorting step is performed, if disabled, no additional sorting is needed.
*/
ORDER_MAP_AND_OBJECT_LITERAL_ENTRIES_BY_KEYS?: boolean;
/**
* Feature that defines default property serialization order used for Class fields
* (note: does not apply to `Map` or Object Literals serialization!):
* if enabled, default ordering is alphabetic
* (similar to how {@link JsonPropertyOrder} with {@link JsonPropertyOrderOptions.alphabetic} works);
* if disabled, order is unspecified (based on what JavaScript gives us, which may be declaration order, but is not guaranteed).
*/
SORT_PROPERTIES_ALPHABETICALLY?: boolean;
/**
* Feature that can be enabled to make root value wrapped within a single property JSON object, where key as the "root name".
*/
WRAP_ROOT_VALUE?: boolean;
/**
* Feature that determines whether `NaN` values should be serialized as `0` or not.
*/
WRITE_NAN_AS_ZERO?: boolean;
/**
* Feature that determines whether positive `Infinity` values should be serialized as `Number.MAX_SAFE_INTEGER` or not.
*/
WRITE_POSITIVE_INFINITY_AS_NUMBER_MAX_SAFE_INTEGER?: boolean;
/**
* Feature that determines whether positive `Infinity` values should be serialized as `Number.MAX_VALUE` or not.
*/
WRITE_POSITIVE_INFINITY_AS_NUMBER_MAX_VALUE?: boolean;
/**
* Feature that determines whether negative `Infinity` values should be serialized as `Number.MIN_SAFE_INTEGER` or not.
*/
WRITE_NEGATIVE_INFINITY_AS_NUMBER_MIN_SAFE_INTEGER?: boolean;
/**
* Feature that determines whether negative `Infinity` values should be serialized as `Number.MIN_VALUE` or not.
*/
WRITE_NEGATIVE_INFINITY_AS_NUMBER_MIN_VALUE?: boolean;
/**
* Feature that determines whether `Date` values are to be serialized as numeric time stamps or not.
*/
WRITE_DATES_AS_TIMESTAMPS?: boolean;
/**
* Feature that determines whether Dates used as `Map` or Object Literal keys
* are serialized as time stamps or not (if not, will be serialized as textual values).
*/
WRITE_DATE_KEYS_AS_TIMESTAMPS?: boolean;
/**
* Feature that determines what happens when a direct self-reference is detected by
* a Class (and no Object Id handling is enabled for it): if enabled write that reference as `null`;
* if disabled, default behavior is used (which will try to serialize usually resulting in exception).
* But if {@link FAIL_ON_SELF_REFERENCES} is enabled, this property is ignored.
*/
WRITE_SELF_REFERENCES_AS_NULL?: boolean;
}
/**
* Variable that defines default feature values for {@link ObjectMapper} and {@link JsonStringifier}.
*/
export const DefaultSerializationFeatureValues: SerializationFeature = {
/**
* {@link SerializationFeature.DEFAULT_PROPERTY_INCLUSION}
*/
DEFAULT_PROPERTY_INCLUSION: null,
/**
* {@link SerializationFeature.FAIL_ON_SELF_REFERENCES}
*/
FAIL_ON_SELF_REFERENCES: true,
/**
* {@link SerializationFeature.ORDER_MAP_AND_OBJECT_LITERAL_ENTRIES_BY_KEYS}
*/
ORDER_MAP_AND_OBJECT_LITERAL_ENTRIES_BY_KEYS: false,
/**
* {@link SerializationFeature.SORT_PROPERTIES_ALPHABETICALLY}
*/
SORT_PROPERTIES_ALPHABETICALLY: false,
/**
* {@link SerializationFeature.WRAP_ROOT_VALUE}
*/
WRAP_ROOT_VALUE: false,
/**
* {@link SerializationFeature.WRITE_NAN_AS_ZERO}
*/
WRITE_NAN_AS_ZERO: false,
/**
* {@link SerializationFeature.WRITE_POSITIVE_INFINITY_AS_NUMBER_MAX_SAFE_INTEGER}
*/
WRITE_POSITIVE_INFINITY_AS_NUMBER_MAX_SAFE_INTEGER: false,
/**
* {@link SerializationFeature.WRITE_POSITIVE_INFINITY_AS_NUMBER_MAX_VALUE}
*/
WRITE_POSITIVE_INFINITY_AS_NUMBER_MAX_VALUE: false,
/**
* {@link SerializationFeature.WRITE_NEGATIVE_INFINITY_AS_NUMBER_MIN_SAFE_INTEGER}
*/
WRITE_NEGATIVE_INFINITY_AS_NUMBER_MIN_SAFE_INTEGER: false,
/**
* {@link SerializationFeature.WRITE_NEGATIVE_INFINITY_AS_NUMBER_MIN_VALUE}
*/
WRITE_NEGATIVE_INFINITY_AS_NUMBER_MIN_VALUE: false,
/**
* {@link SerializationFeature.WRITE_DATES_AS_TIMESTAMPS}
*/
WRITE_DATES_AS_TIMESTAMPS: true,
/**
* {@link SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS}
*/
WRITE_DATE_KEYS_AS_TIMESTAMPS: false,
/**
* {@link SerializationFeature.WRITE_SELF_REFERENCES_AS_NULL}
*/
WRITE_SELF_REFERENCES_AS_NULL: false,
...DefaultCommonFeatureValues
};