10
10
import com .fasterxml .jackson .core .io .SegmentedStringWriter ;
11
11
import com .fasterxml .jackson .core .type .TypeReference ;
12
12
import com .fasterxml .jackson .core .util .*;
13
-
14
13
import com .fasterxml .jackson .databind .cfg .ContextAttributes ;
15
14
import com .fasterxml .jackson .databind .jsonFormatVisitors .JsonFormatVisitorWrapper ;
16
15
import com .fasterxml .jackson .databind .ser .DefaultSerializerProvider ;
@@ -233,7 +232,44 @@ protected ObjectWriter(ObjectWriter base, JsonFactory f)
233
232
public Version version () {
234
233
return com .fasterxml .jackson .databind .cfg .PackageVersion .VERSION ;
235
234
}
236
-
235
+
236
+ /*
237
+ /**********************************************************
238
+ /* Methods sub-classes MUST override, used for constructing
239
+ /* reader instances, (re)configuring parser instances.
240
+ /* Added in 2.5
241
+ /**********************************************************
242
+ */
243
+
244
+ /**
245
+ * Overridable factory method called by various "withXxx()" methods
246
+ *
247
+ * @since 2.5
248
+ */
249
+ protected ObjectWriter _new (ObjectWriter base , JsonFactory f ) {
250
+ return new ObjectWriter (base , f );
251
+ }
252
+
253
+ /**
254
+ * Overridable factory method called by various "withXxx()" methods
255
+ *
256
+ * @since 2.5
257
+ */
258
+ protected ObjectWriter _new (ObjectWriter base , SerializationConfig config ) {
259
+ return new ObjectWriter (base , config );
260
+ }
261
+
262
+ /**
263
+ * Overridable factory method called by various "withXxx()" methods
264
+ *
265
+ * @since 2.5
266
+ */
267
+ protected ObjectWriter _new (ObjectWriter base , SerializationConfig config ,
268
+ JavaType rootType , JsonSerializer <Object > rootSer ,
269
+ PrettyPrinter pp , FormatSchema s , CharacterEscapes escapes ) {
270
+ return new ObjectWriter (base , config , rootType , rootSer , pp , s , escapes );
271
+ }
272
+
237
273
/*
238
274
/**********************************************************
239
275
/* Life-cycle, fluent factories for SerializationFeature
@@ -246,7 +282,7 @@ public Version version() {
246
282
*/
247
283
public ObjectWriter with (SerializationFeature feature ) {
248
284
SerializationConfig newConfig = _config .with (feature );
249
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
285
+ return (newConfig == _config ) ? this : _new (this , newConfig );
250
286
}
251
287
252
288
/**
@@ -255,7 +291,7 @@ public ObjectWriter with(SerializationFeature feature) {
255
291
*/
256
292
public ObjectWriter with (SerializationFeature first , SerializationFeature ... other ) {
257
293
SerializationConfig newConfig = _config .with (first , other );
258
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
294
+ return (newConfig == _config ) ? this : _new (this , newConfig );
259
295
}
260
296
261
297
/**
@@ -264,7 +300,7 @@ public ObjectWriter with(SerializationFeature first, SerializationFeature... oth
264
300
*/
265
301
public ObjectWriter withFeatures (SerializationFeature ... features ) {
266
302
SerializationConfig newConfig = _config .withFeatures (features );
267
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
303
+ return (newConfig == _config ) ? this : _new (this , newConfig );
268
304
}
269
305
270
306
/**
@@ -273,7 +309,7 @@ public ObjectWriter withFeatures(SerializationFeature... features) {
273
309
*/
274
310
public ObjectWriter without (SerializationFeature feature ) {
275
311
SerializationConfig newConfig = _config .without (feature );
276
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
312
+ return (newConfig == _config ) ? this : _new (this , newConfig );
277
313
}
278
314
279
315
/**
@@ -282,7 +318,7 @@ public ObjectWriter without(SerializationFeature feature) {
282
318
*/
283
319
public ObjectWriter without (SerializationFeature first , SerializationFeature ... other ) {
284
320
SerializationConfig newConfig = _config .without (first , other );
285
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
321
+ return (newConfig == _config ) ? this : _new (this , newConfig );
286
322
}
287
323
288
324
/**
@@ -291,7 +327,7 @@ public ObjectWriter without(SerializationFeature first, SerializationFeature...
291
327
*/
292
328
public ObjectWriter withoutFeatures (SerializationFeature ... features ) {
293
329
SerializationConfig newConfig = _config .withoutFeatures (features );
294
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
330
+ return (newConfig == _config ) ? this : _new (this , newConfig );
295
331
}
296
332
297
333
/*
@@ -305,31 +341,31 @@ public ObjectWriter withoutFeatures(SerializationFeature... features) {
305
341
*/
306
342
public ObjectWriter with (JsonGenerator .Feature feature ) {
307
343
SerializationConfig newConfig = _config .with (feature );
308
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
344
+ return (newConfig == _config ) ? this : _new (this , newConfig );
309
345
}
310
346
311
347
/**
312
348
* @since 2.5
313
349
*/
314
350
public ObjectWriter withFeatures (JsonGenerator .Feature ... features ) {
315
351
SerializationConfig newConfig = _config .withFeatures (features );
316
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
352
+ return (newConfig == _config ) ? this : _new (this , newConfig );
317
353
}
318
354
319
355
/**
320
356
* @since 2.5
321
357
*/
322
358
public ObjectWriter without (JsonGenerator .Feature feature ) {
323
359
SerializationConfig newConfig = _config .without (feature );
324
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
360
+ return (newConfig == _config ) ? this : _new (this , newConfig );
325
361
}
326
362
327
363
/**
328
364
* @since 2.5
329
365
*/
330
366
public ObjectWriter withoutFeatures (JsonGenerator .Feature ... features ) {
331
367
SerializationConfig newConfig = _config .withoutFeatures (features );
332
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
368
+ return (newConfig == _config ) ? this : _new (this , newConfig );
333
369
}
334
370
335
371
/*
@@ -348,7 +384,7 @@ public ObjectWriter withoutFeatures(JsonGenerator.Feature... features) {
348
384
*/
349
385
public ObjectWriter with (DateFormat df ) {
350
386
SerializationConfig newConfig = _config .with (df );
351
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
387
+ return (newConfig == _config ) ? this : _new (this , newConfig );
352
388
}
353
389
354
390
/**
@@ -365,7 +401,7 @@ public ObjectWriter withDefaultPrettyPrinter() {
365
401
*/
366
402
public ObjectWriter with (FilterProvider filterProvider ) {
367
403
return (filterProvider == _config .getFilterProvider ()) ? this
368
- : new ObjectWriter (this , _config .withFilters (filterProvider ));
404
+ : _new (this , _config .withFilters (filterProvider ));
369
405
}
370
406
371
407
/**
@@ -380,7 +416,7 @@ public ObjectWriter with(PrettyPrinter pp) {
380
416
if (pp == null ) {
381
417
pp = NULL_PRETTY_PRINTER ;
382
418
}
383
- return new ObjectWriter (this , _config , _rootType , _rootSerializer ,
419
+ return _new (this , _config , _rootType , _rootSerializer ,
384
420
pp , _schema , _characterEscapes );
385
421
}
386
422
@@ -394,7 +430,7 @@ public ObjectWriter with(PrettyPrinter pp) {
394
430
*/
395
431
public ObjectWriter withRootName (String rootName ) {
396
432
SerializationConfig newConfig = _config .withRootName (rootName );
397
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
433
+ return (newConfig == _config ) ? this : _new (this , newConfig );
398
434
}
399
435
400
436
/**
@@ -409,7 +445,7 @@ public ObjectWriter with(FormatSchema schema) {
409
445
return this ;
410
446
}
411
447
_verifySchemaType (schema );
412
- return new ObjectWriter (this , _config , _rootType , _rootSerializer ,
448
+ return _new (this , _config , _rootType , _rootSerializer ,
413
449
_prettyPrinter , schema , _characterEscapes );
414
450
}
415
451
@@ -442,7 +478,7 @@ public ObjectWriter forType(JavaType rootType)
442
478
rootType = rootType .withStaticTyping ();
443
479
rootSer = _prefetchRootSerializer (_config , rootType );
444
480
}
445
- return new ObjectWriter (this , _config , rootType , rootSer ,
481
+ return _new (this , _config , rootType , rootSer ,
446
482
_prettyPrinter , _schema , _characterEscapes );
447
483
}
448
484
@@ -498,17 +534,17 @@ public ObjectWriter withType(TypeReference<?> rootType) {
498
534
*/
499
535
public ObjectWriter withView (Class <?> view ) {
500
536
SerializationConfig newConfig = _config .withView (view );
501
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
537
+ return (newConfig == _config ) ? this : _new (this , newConfig );
502
538
}
503
539
504
540
public ObjectWriter with (Locale l ) {
505
541
SerializationConfig newConfig = _config .with (l );
506
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
542
+ return (newConfig == _config ) ? this : _new (this , newConfig );
507
543
}
508
544
509
545
public ObjectWriter with (TimeZone tz ) {
510
546
SerializationConfig newConfig = _config .with (tz );
511
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
547
+ return (newConfig == _config ) ? this : _new (this , newConfig );
512
548
}
513
549
514
550
/**
@@ -519,7 +555,7 @@ public ObjectWriter with(TimeZone tz) {
519
555
*/
520
556
public ObjectWriter with (Base64Variant b64variant ) {
521
557
SerializationConfig newConfig = _config .with (b64variant );
522
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
558
+ return (newConfig == _config ) ? this : _new (this , newConfig );
523
559
}
524
560
525
561
/**
@@ -529,47 +565,47 @@ public ObjectWriter with(CharacterEscapes escapes) {
529
565
if (_characterEscapes == escapes ) {
530
566
return this ;
531
567
}
532
- return new ObjectWriter (this , _config , _rootType , _rootSerializer ,
568
+ return _new (this , _config , _rootType , _rootSerializer ,
533
569
_prettyPrinter , _schema , escapes );
534
570
}
535
571
536
572
/**
537
573
* @since 2.3
538
574
*/
539
575
public ObjectWriter with (JsonFactory f ) {
540
- return (f == _generatorFactory ) ? this : new ObjectWriter (this , f );
576
+ return (f == _generatorFactory ) ? this : _new (this , f );
541
577
}
542
578
543
579
/**
544
580
* @since 2.3
545
581
*/
546
582
public ObjectWriter with (ContextAttributes attrs ) {
547
583
SerializationConfig newConfig = _config .with (attrs );
548
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
584
+ return (newConfig == _config ) ? this : _new (this , newConfig );
549
585
}
550
586
551
587
/**
552
588
* @since 2.3
553
589
*/
554
590
public ObjectWriter withAttributes (Map <Object ,Object > attrs ) {
555
591
SerializationConfig newConfig = _config .withAttributes (attrs );
556
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
592
+ return (newConfig == _config ) ? this : _new (this , newConfig );
557
593
}
558
594
559
595
/**
560
596
* @since 2.3
561
597
*/
562
598
public ObjectWriter withAttribute (Object key , Object value ) {
563
599
SerializationConfig newConfig = _config .withAttribute (key , value );
564
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
600
+ return (newConfig == _config ) ? this : _new (this , newConfig );
565
601
}
566
602
567
603
/**
568
604
* @since 2.3
569
605
*/
570
606
public ObjectWriter withoutAttribute (Object key ) {
571
607
SerializationConfig newConfig = _config .withoutAttribute (key );
572
- return (newConfig == _config ) ? this : new ObjectWriter (this , newConfig );
608
+ return (newConfig == _config ) ? this : _new (this , newConfig );
573
609
}
574
610
575
611
/*
0 commit comments