@@ -595,9 +595,15 @@ protected ObjectMapper(ObjectMapper src)
595
595
this (src , null );
596
596
}
597
597
598
+ /**
599
+ * Copy constructor with {@link JsonFactory} override: mostly needed
600
+ * to support {@link #copyWith(JsonFactory)} method.
601
+ *
602
+ * @since 2.14
603
+ */
598
604
protected ObjectMapper (ObjectMapper src , JsonFactory factory )
599
605
{
600
- _jsonFactory = factory != null ? factory : src ._jsonFactory .copy ();
606
+ _jsonFactory = ( factory != null ) ? factory : src ._jsonFactory .copy ();
601
607
_jsonFactory .setCodec (this );
602
608
_subtypeResolver = src ._subtypeResolver .copy ();
603
609
_typeFactory = src ._typeFactory ;
@@ -608,10 +614,10 @@ protected ObjectMapper(ObjectMapper src, JsonFactory factory)
608
614
609
615
RootNameLookup rootNames = new RootNameLookup ();
610
616
_serializationConfig = new SerializationConfig (src ._serializationConfig ,
611
- _subtypeResolver , _mixIns , rootNames , _configOverrides );
617
+ _subtypeResolver , _mixIns , rootNames , _configOverrides );
612
618
_deserializationConfig = new DeserializationConfig (src ._deserializationConfig ,
613
- _subtypeResolver , _mixIns , rootNames , _configOverrides ,
614
- _coercionConfigs );
619
+ _subtypeResolver , _mixIns , rootNames , _configOverrides ,
620
+ _coercionConfigs );
615
621
_serializerProvider = src ._serializerProvider .copy ();
616
622
_deserializationContext = src ._deserializationContext .copy ();
617
623
@@ -663,12 +669,12 @@ public ObjectMapper(JsonFactory jf,
663
669
_configOverrides = new ConfigOverrides ();
664
670
_coercionConfigs = new CoercionConfigs ();
665
671
_serializationConfig = new SerializationConfig (base ,
666
- _subtypeResolver , mixins , rootNames , _configOverrides ,
667
- DatatypeFeatures .defaultFeatures ());
672
+ _subtypeResolver , mixins , rootNames , _configOverrides ,
673
+ DatatypeFeatures .defaultFeatures ());
668
674
_deserializationConfig = new DeserializationConfig (base ,
669
- _subtypeResolver , mixins , rootNames , _configOverrides ,
670
- _coercionConfigs ,
671
- DatatypeFeatures .defaultFeatures ());
675
+ _subtypeResolver , mixins , rootNames , _configOverrides ,
676
+ _coercionConfigs ,
677
+ DatatypeFeatures .defaultFeatures ());
672
678
673
679
// Some overrides we may need
674
680
final boolean needOrder = _jsonFactory .requiresPropertyOrdering ();
@@ -720,6 +726,20 @@ public ObjectMapper copy() {
720
726
return new ObjectMapper (this );
721
727
}
722
728
729
+ /**
730
+ * Method for creating a new {@link ObjectMapper} instance that
731
+ * has same initial configuration as this instance (similar to how
732
+ * {@link #copy()} works, with one additional difference: that of
733
+ * alternate underlying {@link JsonFactory} to use.
734
+ * instance.
735
+ *
736
+ * @since 2.14
737
+ *
738
+ * @param factory Token stream factory to use for low-level streaming
739
+ * reading (parsing) and writing (generation)
740
+ *
741
+ * @return Newly created mapper instance
742
+ */
723
743
public ObjectMapper copyWith (JsonFactory factory ) {
724
744
_checkInvalidCopy (ObjectMapper .class );
725
745
return new ObjectMapper (this , factory );
@@ -732,8 +752,8 @@ protected void _checkInvalidCopy(Class<?> exp)
732
752
{
733
753
if (getClass () != exp ) {
734
754
// 10-Nov-2016, tatu: could almost use `ClassUtil.verifyMustOverride()` but not quite
735
- throw new IllegalStateException ("Failed copy(): " +getClass ().getName ()
736
- +" (version: " +version ()+") does not override copy(); it has to" );
755
+ throw new IllegalStateException ("Failed copy()/copyWith() : " +getClass ().getName ()
756
+ +" (version: " +version ()+") does not override copy()/copyWith() ; it has to" );
737
757
}
738
758
}
739
759
0 commit comments