Skip to content

Commit 789df88

Browse files
committed
Add missing config methods, testing, for ObjectWriter too
1 parent 648b209 commit 789df88

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,13 @@ public boolean isEnabled(JsonParser.Feature f) {
961961
return _config.isEnabled(f, _parserFactory);
962962
}
963963

964+
/**
965+
* @since 2.11
966+
*/
967+
public boolean isEnabled(StreamReadFeature f) {
968+
return _config.isEnabled(f.mappedFeature(), _parserFactory);
969+
}
970+
964971
/**
965972
* @since 2.2
966973
*/

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

+28-1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,26 @@ public ObjectWriter withoutFeatures(JsonGenerator.Feature... features) {
349349
return _new(this, _config.withoutFeatures(features));
350350
}
351351

352+
/*
353+
/**********************************************************
354+
/* Life-cycle, fluent factories for StreamWriteFeature (2.11)
355+
/**********************************************************
356+
*/
357+
358+
/**
359+
* @since 2.11
360+
*/
361+
public ObjectWriter with(StreamWriteFeature feature) {
362+
return _new(this, _config.with(feature.mappedFeature()));
363+
}
364+
365+
/**
366+
* @since 2.11
367+
*/
368+
public ObjectWriter without(StreamWriteFeature feature) {
369+
return _new(this, _config.without(feature.mappedFeature()));
370+
}
371+
352372
/*
353373
/**********************************************************
354374
/* Life-cycle, fluent factories for FormatFeature (2.7)
@@ -908,7 +928,14 @@ public boolean isEnabled(JsonParser.Feature f) {
908928
public boolean isEnabled(JsonGenerator.Feature f) {
909929
return _generatorFactory.isEnabled(f);
910930
}
911-
931+
932+
/**
933+
* @since 2.11
934+
*/
935+
public boolean isEnabled(StreamWriteFeature f) {
936+
return _generatorFactory.isEnabled(f);
937+
}
938+
912939
/**
913940
* @since 2.2
914941
*/

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

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ public void testFeatureSettings() throws Exception
112112

113113
// and another one
114114
assertSame(r, r.with(r.getConfig()));
115+
116+
// and with StreamReadFeatures
117+
r = MAPPER.reader();
118+
assertFalse(r.isEnabled(StreamReadFeature.IGNORE_UNDEFINED));
119+
ObjectReader r2 = r.with(StreamReadFeature.IGNORE_UNDEFINED);
120+
assertTrue(r2.isEnabled(StreamReadFeature.IGNORE_UNDEFINED));
121+
ObjectReader r3 = r2.without(StreamReadFeature.IGNORE_UNDEFINED);
122+
assertFalse(r3.isEnabled(StreamReadFeature.IGNORE_UNDEFINED));
115123
}
116124

117125
public void testFeatureSettingsDeprecated() throws Exception

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ public void testFeatureSettings() throws Exception
234234
ObjectWriter w = MAPPER.writer();
235235
assertFalse(w.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES));
236236
assertFalse(w.isEnabled(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION));
237+
assertFalse(w.isEnabled(StreamWriteFeature.STRICT_DUPLICATE_DETECTION));
238+
237239
ObjectWriter newW = w.with(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS,
238240
SerializationFeature.INDENT_OUTPUT);
239241
assertNotSame(w, newW);
@@ -267,8 +269,11 @@ public void testGeneratorFeatures() throws Exception
267269
assertTrue(w.isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET));
268270
assertNotSame(w, w.without(JsonGenerator.Feature.AUTO_CLOSE_TARGET));
269271
assertNotSame(w, w.withoutFeatures(JsonGenerator.Feature.AUTO_CLOSE_TARGET));
272+
273+
assertFalse(w.isEnabled(StreamWriteFeature.STRICT_DUPLICATE_DETECTION));
274+
assertNotSame(w, w.with(StreamWriteFeature.STRICT_DUPLICATE_DETECTION));
270275
}
271-
276+
272277
/*
273278
/**********************************************************
274279
/* Test methods, failures

0 commit comments

Comments
 (0)