Skip to content

Commit 5183922

Browse files
committed
Backport #913 fix in 2.6
1 parent a7b26eb commit 5183922

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

release-notes/CREDITS

+5-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ Andy Wilkinson (wilkinsona@github)
309309
(2.6.1)
310310

311311
lufe66@github:
312-
313312
* Reported 894: When using withFactory on ObjectMapper, the created Factory has a TypeParser
314313
which still has the original Factory
315314
(2.6.2)
315+
316+
Daniel Walker (dsw2127@github)
317+
* Reported, contributed fix for #913: `ObjectMapper.copy()` does not preserve
318+
`MappingJsonFactory` features
319+
(2.6.2)

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Project: jackson-databind
1010
which still has the original Factory
1111
(reported by lufe66@github)
1212
#899: Problem serializing `ObjectReader` (and possibly `ObjectMapper`)
13+
#913: ObjectMapper.copy does not preserve MappingJsonFactory features
14+
(reported, fixed by Daniel W)
1315

1416
2.6.1 (09-Aug-2015)
1517

src/main/java/com/fasterxml/jackson/databind/MappingJsonFactory.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public MappingJsonFactory(ObjectMapper mapper)
3333
}
3434
}
3535

36+
public MappingJsonFactory(JsonFactory src, ObjectMapper mapper)
37+
{
38+
super(src, mapper);
39+
if (mapper == null) {
40+
setCodec(new ObjectMapper(this));
41+
}
42+
}
43+
3644
/**
3745
* We'll override the method to return more specific type; co-variance
3846
* helps here
@@ -46,7 +54,7 @@ public JsonFactory copy()
4654
{
4755
_checkInvalidCopy(MappingJsonFactory.class);
4856
// note: as with base class, must NOT copy mapper reference
49-
return new MappingJsonFactory(null);
57+
return new MappingJsonFactory(this, null);
5058
}
5159

5260
/*

src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public void testCopy() throws Exception
159159
assertFalse(m.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
160160
InjectableValues inj = new InjectableValues.Std();
161161
m.setInjectableValues(inj);
162+
assertFalse(m.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
163+
m.enable(JsonParser.Feature.ALLOW_COMMENTS);
164+
assertTrue(m.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
162165

163166
// // First: verify that handling of features is decoupled:
164167

@@ -193,6 +196,10 @@ public void testCopy() throws Exception
193196
assertEquals(0, m2.getSerializationConfig().mixInCount());
194197
assertEquals(1, m.getDeserializationConfig().mixInCount());
195198
assertEquals(0, m2.getDeserializationConfig().mixInCount());
199+
200+
// [Issue#913]: Ensure JsonFactory Features copied
201+
assertTrue(m2.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
202+
196203
}
197204

198205
public void testAnnotationIntrospectorCopyin()

0 commit comments

Comments
 (0)