@@ -204,6 +204,46 @@ public void testCopyOfSubtypeResolver2785() throws Exception {
204
204
assertNotNull (result );
205
205
}
206
206
207
+ public void testCopyWith () throws JsonProcessingException {
208
+ ObjectMapper mapper = new ObjectMapper ();
209
+ //configuring some settings to non-defaults
210
+ mapper .configure (DeserializationFeature .FAIL_ON_NULL_FOR_PRIMITIVES , true );
211
+ mapper .configure (DeserializationFeature .READ_UNKNOWN_ENUM_VALUES_AS_NULL , true );
212
+ mapper .configure (SerializationFeature .INDENT_OUTPUT , true );
213
+ mapper .configure (SerializationFeature .FAIL_ON_SELF_REFERENCES , true );
214
+ JsonFactory newFactory = JsonFactory .builder ()
215
+ .configure (JsonFactory .Feature .USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING , false )
216
+ .build ();
217
+ ObjectMapper copiedMapper = mapper .copyWith (newFactory );
218
+ String json = "{ \" color\" : \" Black\" , \" free\" : \" true\" , \" pages\" : \" 204.04\" }" ;
219
+ JsonNode readResult = copiedMapper .readTree (json );
220
+ //validate functionality
221
+ assertEquals ("Black" , readResult .get ("color" ).asText ());
222
+ assertEquals (true , readResult .get ("free" ).asBoolean ());
223
+ assertEquals (204 , readResult .get ("pages" ).asInt ());
224
+ String readResultAsString = "{\n \" color\" : \" Black\" ,\n \" free\" : \" true\" ,\n \" pages\" : \" 204.04\" \n }" ;
225
+ System .out .println (mapper .writeValueAsString (readResult ));
226
+ assertEquals (readResultAsString , mapper .writeValueAsString (readResult ));
227
+
228
+ //validate properties
229
+ Boolean mapperConfig1 = mapper ._deserializationConfig .isEnabled (DeserializationFeature .FAIL_ON_NULL_FOR_PRIMITIVES );
230
+ Boolean copiedMapperConfig1 = copiedMapper ._deserializationConfig .isEnabled (DeserializationFeature .FAIL_ON_NULL_FOR_PRIMITIVES );
231
+ Boolean mapperConfig2 = mapper ._deserializationConfig .isEnabled (DeserializationFeature .READ_UNKNOWN_ENUM_VALUES_AS_NULL );
232
+ Boolean copiedMapperConfig2 = copiedMapper ._deserializationConfig .isEnabled (DeserializationFeature .READ_UNKNOWN_ENUM_VALUES_AS_NULL );
233
+ Boolean mapperConfig3 = mapper ._serializationConfig .isEnabled (SerializationFeature .INDENT_OUTPUT );
234
+ Boolean copiedMapperConfig3 = copiedMapper ._serializationConfig .isEnabled (SerializationFeature .INDENT_OUTPUT );
235
+ Boolean mapperConfig4 = mapper ._serializationConfig .isEnabled (SerializationFeature .FAIL_ON_SELF_REFERENCES );
236
+ Boolean copiedMapperConfig4 = copiedMapper ._serializationConfig .isEnabled (SerializationFeature .FAIL_ON_SELF_REFERENCES );
237
+ assertNotSame (mapper .getFactory (), copiedMapper .getFactory ());
238
+ assertSame (mapperConfig1 , copiedMapperConfig1 );
239
+ assertSame (mapperConfig2 , copiedMapperConfig2 );
240
+ assertSame (mapperConfig3 , copiedMapperConfig3 );
241
+ assertSame (mapperConfig4 , copiedMapperConfig4 );
242
+ assertNotSame (mapper .getFactory ().isEnabled (JsonFactory .Feature .USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING ),
243
+ copiedMapper .getFactory ().isEnabled (JsonFactory .Feature .USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING )
244
+ );
245
+ }
246
+
207
247
public void testFailedCopy () throws Exception
208
248
{
209
249
NoCopyMapper src = new NoCopyMapper ();
0 commit comments