18
18
*<p>
19
19
* NOTE: version 2.9 contains significant attempt at simplifying interface,
20
20
* as well as giving format implementation (via {@link JsonGenerator}) more
21
- * control over actual serialization details.
21
+ * control over actual serialization details. Minor changes are required to change
22
+ * call pattern so that return value of "prefix" write needs to be passed to "suffix"
23
+ * write.
22
24
*/
23
25
public abstract class TypeSerializer
24
26
{
@@ -119,6 +121,12 @@ public WritableTypeId typeId(Object value, Class<?> typeForId,
119
121
* Method called to write initial part of type information for given
120
122
* value, along with possible wrapping to use: details are specified
121
123
* by `typeId` argument.
124
+ * Note that for structured types (Object, Array), this call will add
125
+ * necessary start token so it should NOT be explicitly written, unlike
126
+ * with non-type-id value writes.
127
+ *<p>
128
+ * See {@link #writeTypeSuffix(JsonGenerator, WritableTypeId)} for a complete
129
+ * example of typical usage.
122
130
*
123
131
* @param g Generator to use for outputting type id and possible wrapping
124
132
* @param typeId Details of what type id is to be written, how.
@@ -129,6 +137,25 @@ public abstract WritableTypeId writeTypePrefix(JsonGenerator g,
129
137
WritableTypeId typeId ) throws IOException ;
130
138
131
139
/**
140
+ * Method that should be called after {@link #writeTypePrefix(JsonGenerator, WritableTypeId)}
141
+ * and matching value write have called, passing {@link WritableTypeId} returned.
142
+ * Usual idiom is:
143
+ *<pre>
144
+ * // Indicator generator that type identifier may be needed; generator may write
145
+ * // one as suggested, modify information, or take some other action
146
+ * // NOTE! For Object/Array types, this will ALSO write start marker!
147
+ * WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen,
148
+ * typeSer.typeId(value, JsonToken.START_OBJECT));
149
+ *
150
+ * // serializing actual value for which TypeId may have been written... like
151
+ * // NOTE: do NOT write START_OBJECT before OR END_OBJECT after:
152
+ * g.writeStringField("message", "Hello, world!"
153
+ *
154
+ * // matching type suffix call to let generator chance to add suffix, if any
155
+ * // NOTE! For Object/Array types, this will ALSO write end marker!
156
+ * typeSer.writeTypeSuffix(gen, typeIdDef);
157
+ *</pre>
158
+ *
132
159
* @since 2.9
133
160
*/
134
161
public abstract WritableTypeId writeTypeSuffix (JsonGenerator g ,
@@ -141,110 +168,107 @@ public abstract WritableTypeId writeTypeSuffix(JsonGenerator g,
141
168
*/
142
169
143
170
/**
144
- * Method called to write initial part of type information for given
145
- * value, when it will be output as scalar JSON value (not as JSON
146
- * Object or Array).
147
- * This means that the context after call cannot be that of JSON Object;
148
- * it may be Array or root context.
149
- *
150
- * @param value Value that will be serialized, for which type information is
151
- * to be written
152
- * @param g Generator to use for writing type information
171
+ * DEPRECATED: now equivalent to:
172
+ *{@code writeTypePrefix(g, typeId(value, JsonToken.VALUE_STRING));}.
173
+ * See {@link #writeTypePrefix} for more info.
174
+ *
175
+ * @deprecated Since 2.9 use {@link #writeTypePrefix(JsonGenerator, WritableTypeId) instead
153
176
*/
154
177
@ Deprecated // since 2.9
155
178
public void writeTypePrefixForScalar (Object value , JsonGenerator g ) throws IOException {
156
179
writeTypePrefix (g , typeId (value , JsonToken .VALUE_STRING ));
157
180
}
158
181
159
182
/**
160
- * Method called to write initial part of type information for given
161
- * value, when it will be output as JSON Object value (not as JSON
162
- * Array or scalar).
163
- * This means that context after call must be JSON Object, meaning that
164
- * caller can then proceed to output field entries.
165
- *
166
- * @param value Value that will be serialized, for which type information is
167
- * to be written
168
- * @param g Generator to use for writing type information
183
+ * DEPRECATED: now equivalent to:
184
+ *{@code writeTypePrefix(g, typeId(value, JsonToken.START_OBJECT));}.
185
+ * See {@link #writeTypePrefix} for more info.
186
+ *
187
+ * @deprecated Since 2.9 use {@link #writeTypePrefix(JsonGenerator, WritableTypeId) instead
169
188
*/
170
189
@ Deprecated // since 2.9
171
190
public void writeTypePrefixForObject (Object value , JsonGenerator g ) throws IOException {
172
191
writeTypePrefix (g , typeId (value , JsonToken .START_OBJECT ));
173
192
}
174
193
175
194
/**
176
- * Method called to write initial part of type information for given
177
- * value, when it will be output as JSON Array value (not as JSON
178
- * Object or scalar).
179
- * This means that context after call must be JSON Array, that is, there
180
- * must be an open START_ARRAY to write contents in.
181
- *
182
- * @param value Value that will be serialized, for which type information is
183
- * to be written
184
- * @param g Generator to use for writing type information
195
+ * DEPRECATED: now equivalent to:
196
+ *{@code writeTypePrefix(g, typeId(value, JsonToken.START_ARRAY));}.
197
+ * See {@link #writeTypePrefix} for more info.
198
+ *
199
+ * @deprecated Since 2.9 use {@link #writeTypePrefix(JsonGenerator, WritableTypeId) instead
185
200
*/
186
201
@ Deprecated // since 2.9
187
202
public void writeTypePrefixForArray (Object value , JsonGenerator g ) throws IOException {
188
203
writeTypePrefix (g , typeId (value , JsonToken .START_ARRAY ));
189
204
}
190
205
191
206
/**
192
- * Method called after value has been serialized, to close any scopes opened
193
- * by earlier matching call to {@link #writeTypePrefixForScalar}.
194
- * Actual action to take may depend on various factors, but has to match with
195
- * action {@link #writeTypePrefixForScalar} did (close array or object; or do nothing).
207
+ * DEPRECATED: now equivalent to:
208
+ *{@code writeTypeSuffix(g, typeId(value, JsonToken.VALUE_STRING));}.
209
+ * See {@link #writeTypeSuffix} for more info.
210
+ *
211
+ * @deprecated Since 2.9 use {@link #writeTypeSuffix(JsonGenerator, WritableTypeId) instead
196
212
*/
197
213
@ Deprecated // since 2.9
198
214
public void writeTypeSuffixForScalar (Object value , JsonGenerator g ) throws IOException {
199
215
_writeLegacySuffix (g , typeId (value , JsonToken .VALUE_STRING ));
200
216
}
201
217
202
218
/**
203
- * Method called after value has been serialized, to close any scopes opened
204
- * by earlier matching call to {@link #writeTypePrefixForObject}.
205
- * It needs to write closing END_OBJECT marker, and any other decoration
206
- * that needs to be matched.
219
+ * DEPRECATED: now equivalent to:
220
+ *{@code writeTypeSuffix(g, typeId(value, JsonToken.START_OBJECT));}.
221
+ * See {@link #writeTypeSuffix} for more info.
222
+ *
223
+ * @deprecated Since 2.9 use {@link #writeTypeSuffix(JsonGenerator, WritableTypeId) instead
207
224
*/
208
225
@ Deprecated // since 2.9
209
226
public void writeTypeSuffixForObject (Object value , JsonGenerator g ) throws IOException {
210
227
_writeLegacySuffix (g , typeId (value , JsonToken .START_OBJECT ));
211
228
}
212
229
213
230
/**
214
- * Method called after value has been serialized, to close any scopes opened
215
- * by earlier matching call to {@link #writeTypeSuffixForScalar}.
216
- * It needs to write closing END_ARRAY marker, and any other decoration
217
- * that needs to be matched.
231
+ * DEPRECATED: now equivalent to:
232
+ *{@code writeTypeSuffix(g, typeId(value, JsonToken.START_ARRAY));}.
233
+ * See {@link #writeTypeSuffix} for more info.
234
+ *
235
+ * @deprecated Since 2.9 use {@link #writeTypeSuffix(JsonGenerator, WritableTypeId) instead
218
236
*/
219
237
@ Deprecated // since 2.9
220
238
public void writeTypeSuffixForArray (Object value , JsonGenerator g ) throws IOException {
221
239
_writeLegacySuffix (g , typeId (value , JsonToken .START_ARRAY ));
222
240
}
223
241
224
242
/**
225
- * Alternative version of the prefix-for-scalar method, which is given
226
- * actual type to use (instead of using exact type of the value); typically
227
- * a super type of actual value type
243
+ * DEPRECATED: now equivalent to:
244
+ *{@code writeTypePrefix(g, typeId(value, type, JsonToken.VALUE_STRING));}.
245
+ * See {@link #writeTypePrefix} for more info.
246
+ *
247
+ * @deprecated Since 2.9 use {@link #writeTypePrefix(JsonGenerator, WritableTypeId) instead
228
248
*/
229
249
@ Deprecated // since 2.9
230
250
public void writeTypePrefixForScalar (Object value , JsonGenerator g , Class <?> type ) throws IOException {
231
251
writeTypePrefix (g , typeId (value , type , JsonToken .VALUE_STRING ));
232
252
}
233
253
234
254
/**
235
- * Alternative version of the prefix-for-object method, which is given
236
- * actual type to use (instead of using exact type of the value); typically
237
- * a super type of actual value type
255
+ * DEPRECATED: now equivalent to:
256
+ *{@code writeTypePrefix(g, typeId(value, type, JsonToken.START_OBJECT));}.
257
+ * See {@link #writeTypePrefix} for more info.
258
+ *
259
+ * @deprecated Since 2.9 use {@link #writeTypePrefix(JsonGenerator, WritableTypeId) instead
238
260
*/
239
261
@ Deprecated // since 2.9
240
262
public void writeTypePrefixForObject (Object value , JsonGenerator g , Class <?> type ) throws IOException {
241
263
writeTypePrefix (g , typeId (value , type , JsonToken .START_OBJECT ));
242
264
}
243
265
244
266
/**
245
- * Alternative version of the prefix-for-array method, which is given
246
- * actual type to use (instead of using exact type of the value); typically
247
- * a super type of actual value type
267
+ * DEPRECATED: now equivalent to:
268
+ *{@code writeTypePrefix(g, typeId(value, type, JsonToken.START_ARRAY));}.
269
+ * See {@link #writeTypePrefix} for more info.
270
+ *
271
+ * @deprecated Since 2.9 use {@link #writeTypePrefix(JsonGenerator, WritableTypeId) instead
248
272
*/
249
273
@ Deprecated // since 2.9
250
274
public void writeTypePrefixForArray (Object value , JsonGenerator g , Class <?> type ) throws IOException {
@@ -257,31 +281,61 @@ public void writeTypePrefixForArray(Object value, JsonGenerator g, Class<?> type
257
281
/**********************************************************
258
282
*/
259
283
284
+ /**
285
+ * DEPRECATED: now equivalent to:
286
+ *{@code writeTypePrefix(g, typeId(value, JsonToken.VALUE_STRING, typeId));}.
287
+ * See {@link #writeTypePrefix} for more info.
288
+ *
289
+ * @deprecated Since 2.9 use {@link #writeTypePrefix(JsonGenerator, WritableTypeId) instead
290
+ */
260
291
@ Deprecated // since 2.9
261
292
public void writeCustomTypePrefixForScalar (Object value , JsonGenerator g , String typeId ) throws IOException {
262
293
writeTypePrefix (g , typeId (value , JsonToken .VALUE_STRING , typeId ));
263
294
}
264
295
296
+ /**
297
+ * DEPRECATED: now equivalent to:
298
+ *{@code writeTypePrefix(g, typeId(value, JsonToken.START_OBJECT, typeId));}.
299
+ * See {@link #writeTypePrefix} for more info.
300
+ *
301
+ * @deprecated Since 2.9 use {@link #writeTypePrefix(JsonGenerator, WritableTypeId) instead
302
+ */
265
303
@ Deprecated // since 2.9
266
304
public void writeCustomTypePrefixForObject (Object value , JsonGenerator g , String typeId ) throws IOException {
267
305
writeTypePrefix (g , typeId (value , JsonToken .START_OBJECT , typeId ));
268
306
}
269
307
308
+ /**
309
+ * DEPRECATED: now equivalent to:
310
+ *{@code writeTypePrefix(g, typeId(value, JsonToken.START_ARRAY, typeId));}.
311
+ * See {@link #writeTypePrefix} for more info.
312
+ *
313
+ * @deprecated Since 2.9 use {@link #writeTypePrefix(JsonGenerator, WritableTypeId) instead
314
+ */
270
315
@ Deprecated // since 2.9
271
316
public void writeCustomTypePrefixForArray (Object value , JsonGenerator g , String typeId ) throws IOException {
272
317
writeTypePrefix (g , typeId (value , JsonToken .START_ARRAY , typeId ));
273
318
}
274
319
320
+ /**
321
+ * @deprecated Since 2.9 use {@link #writeTypeSuffix(JsonGenerator, WritableTypeId) instead
322
+ */
275
323
@ Deprecated // since 2.9
276
324
public void writeCustomTypeSuffixForScalar (Object value , JsonGenerator g , String typeId ) throws IOException {
277
325
_writeLegacySuffix (g , typeId (value , JsonToken .VALUE_STRING , typeId ));
278
326
}
279
327
328
+ /**
329
+ * @deprecated Since 2.9 use {@link #writeTypeSuffix(JsonGenerator, WritableTypeId) instead
330
+ */
280
331
@ Deprecated // since 2.9
281
332
public void writeCustomTypeSuffixForObject (Object value , JsonGenerator g , String typeId ) throws IOException {
282
333
_writeLegacySuffix (g , typeId (value , JsonToken .START_OBJECT , typeId ));
283
334
}
284
335
336
+ /**
337
+ * @deprecated Since 2.9 use {@link #writeTypeSuffix(JsonGenerator, WritableTypeId) instead
338
+ */
285
339
@ Deprecated // since 2.9
286
340
public void writeCustomTypeSuffixForArray (Object value , JsonGenerator g , String typeId ) throws IOException {
287
341
_writeLegacySuffix (g , typeId (value , JsonToken .START_ARRAY , typeId ));
0 commit comments