@@ -85,24 +85,24 @@ export declare class JsonConvert {
85
85
* Determines the rule of how JSON properties shall be matched with class properties during deserialization.
86
86
*
87
87
* You may assign the following values:
88
- * - CASE_STRICT: JSON properties need to match exactly the names in the decorators
89
- * - CASE_INSENSITIVE: JSON properties need to match names in the decorators, but names they are not case sensitive
88
+ * - PropertyMatchingRule. CASE_STRICT: JSON properties need to match exactly the names in the decorators
89
+ * - PropertyMatchingRule. CASE_INSENSITIVE: JSON properties need to match names in the decorators, but names they are not case sensitive
90
90
*/
91
91
private _propertyMatchingRule ;
92
92
/**
93
93
* Determines the rule of how JSON properties shall be matched with class properties during deserialization.
94
94
*
95
95
* You may assign the following values:
96
- * - CASE_STRICT: JSON properties need to match exactly the names in the decorators
97
- * - CASE_INSENSITIVE: JSON properties need to match names in the decorators, but names they are not case sensitive
96
+ * - PropertyMatchingRule. CASE_STRICT: JSON properties need to match exactly the names in the decorators
97
+ * - PropertyMatchingRule. CASE_INSENSITIVE: JSON properties need to match names in the decorators, but names they are not case sensitive
98
98
* @returns {number }
99
99
*/
100
100
/**
101
- * Determines the rule of how JSON properties shall be matched with class properties during deserialization.
101
+ * Determines the rule of how JSON properties shall be matched with class properties during deserialization.
102
102
*
103
103
* You may assign the following values:
104
- * - CASE_STRICT: JSON properties need to match exactly the names in the decorators
105
- * - CASE_INSENSITIVE: JSON properties need to match names in the decorators, but names they are not case sensitive
104
+ * - PropertyMatchingRule. CASE_STRICT: JSON properties need to match exactly the names in the decorators
105
+ * - PropertyMatchingRule. CASE_INSENSITIVE: JSON properties need to match names in the decorators, but names they are not case sensitive
106
106
* @param value
107
107
*/
108
108
propertyMatchingRule : number ;
@@ -122,96 +122,96 @@ export declare class JsonConvert {
122
122
*
123
123
* @param data object or array of objects
124
124
*
125
- * @returns { any } the JSON object
125
+ * @returns the JSON object
126
126
*
127
- * @throws an exception in case of failure
127
+ * @throws an Error in case of failure
128
128
*
129
129
* @author Andreas Aeschlimann, DHlab, University of Basel, Switzerland
130
130
* @see https://www.npmjs.com/package/json2typescript full documentation
131
131
*/
132
- serialize ( data : any ) : any ;
132
+ serialize < T > ( data : T | T [ ] ) : any | any [ ] ;
133
133
/**
134
134
* Tries to serialize a TypeScript object to a JSON object.
135
135
*
136
136
* @param instance TypeScript instance
137
137
*
138
- * @returns { any } the JSON object
138
+ * @returns the JSON object
139
139
*
140
- * @throws an exception in case of failure
140
+ * @throws an Error in case of failure
141
141
*
142
142
* @author Andreas Aeschlimann, DHlab, University of Basel, Switzerland
143
143
* @see https://www.npmjs.com/package/json2typescript full documentation
144
144
*/
145
- serializeObject ( instance : any ) : any ;
145
+ serializeObject < T > ( instance : T ) : any ;
146
146
/**
147
147
* Tries to serialize a TypeScript array to a JSON array.
148
148
*
149
149
* @param instanceArray array of TypeScript instances
150
150
*
151
- * @returns { any[] } the JSON array
151
+ * @returns the JSON array
152
152
*
153
- * @throws an exception in case of failure
153
+ * @throws an Error in case of failure
154
154
*
155
155
* @author Andreas Aeschlimann, DHlab, University of Basel, Switzerland
156
156
* @see https://www.npmjs.com/package/json2typescript full documentation
157
157
*/
158
- serializeArray ( instanceArray : any [ ] ) : any [ ] ;
158
+ serializeArray < T > ( instanceArray : T [ ] ) : any [ ] ;
159
159
/**
160
160
* Tries to deserialize given JSON to a TypeScript object or array of objects.
161
161
*
162
162
* @param json the JSON as object or array
163
163
* @param classReference the class reference
164
164
*
165
- * @returns { any } the deserialized data (TypeScript instance or array of TypeScript instances)
165
+ * @returns the deserialized data (TypeScript instance or array of TypeScript instances)
166
166
*
167
- * @throws an exception in case of failure
167
+ * @throws an Error in case of failure
168
168
*
169
169
* @author Andreas Aeschlimann, DHlab, University of Basel, Switzerland
170
170
* @see https://www.npmjs.com/package/json2typescript full documentation
171
171
*/
172
- deserialize ( json : any , classReference : {
173
- new ( ) : any ;
174
- } ) : any ;
172
+ deserialize < T > ( json : any , classReference : {
173
+ new ( ) : T ;
174
+ } ) : T | T [ ] ;
175
175
/**
176
176
* Tries to deserialize a JSON object to a TypeScript object.
177
177
*
178
178
* @param jsonObject the JSON object
179
179
* @param classReference the class reference
180
180
*
181
- * @returns { any } the deserialized TypeScript instance
181
+ * @returns the deserialized TypeScript instance
182
182
*
183
- * @throws an exception in case of failure
183
+ * @throws an Error in case of failure
184
184
*
185
185
* @author Andreas Aeschlimann, DHlab, University of Basel, Switzerland
186
186
* @see https://www.npmjs.com/package/json2typescript full documentation
187
187
*/
188
- deserializeObject ( jsonObject : any , classReference : {
189
- new ( ) : any ;
190
- } ) : any ;
188
+ deserializeObject < T > ( jsonObject : any , classReference : {
189
+ new ( ) : T ;
190
+ } ) : T ;
191
191
/**
192
192
* Tries to deserialize a JSON array to a TypeScript array.
193
193
*
194
194
* @param jsonArray the JSON array
195
195
* @param classReference the object class
196
196
*
197
- * @returns { any[] } the deserialized array of TypeScript instances
197
+ * @returns the deserialized array of TypeScript instances
198
198
*
199
- * @throws an exception in case of failure
199
+ * @throws an Error in case of failure
200
200
*
201
201
* @author Andreas Aeschlimann, DHlab, University of Basel, Switzerland
202
202
* @see https://www.npmjs.com/package/json2typescript full documentation
203
203
*/
204
- deserializeArray ( jsonArray : any [ ] , classReference : {
205
- new ( ) : any ;
206
- } ) : any [ ] ;
204
+ deserializeArray < T > ( jsonArray : any [ ] , classReference : {
205
+ new ( ) : T ;
206
+ } ) : T [ ] ;
207
207
/**
208
208
* Tries to find the JSON mapping for a given class property and finally assign the value.
209
209
*
210
210
* @param instance the instance of the class
211
211
* @param classPropertyName the property name
212
212
* @param json the JSON object
213
213
*
214
- * @throws throws an expection in case of failure
214
+ * @throws throws an Error in case of failure
215
215
*/
216
216
private serializeObject_loopProperty ;
217
217
/**
@@ -221,7 +221,7 @@ export declare class JsonConvert {
221
221
* @param classPropertyName the property name
222
222
* @param json the JSON object
223
223
*
224
- * @throws throws an expection in case of failure
224
+ * @throws throws an Error in case of failure
225
225
*/
226
226
private deserializeObject_loopProperty ;
227
227
/**
@@ -243,9 +243,21 @@ export declare class JsonConvert {
243
243
*
244
244
* @returns returns the resulted mapped property
245
245
*
246
- * @throws throws an expection in case of failure
246
+ * @throws an error in case of failure
247
247
*/
248
248
private verifyProperty ;
249
+ /**
250
+ * Gets the value of an object for a given value.
251
+ * If the object does not have the specific key, an Error is thrown.
252
+ *
253
+ * @param data
254
+ * @param key
255
+ *
256
+ * @returns returns the value
257
+ *
258
+ * @throws an Error in case of the key was not found in the object
259
+ */
260
+ private getObjectValue ;
249
261
/**
250
262
* Returns a string representation of the expected json type.
251
263
*
0 commit comments