Skip to content

Commit e7a560a

Browse files
committed
Fix #619: add mapper.isEnabled(FormatRead/WriteFeature) methods
1 parent 9135f53 commit e7a560a

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

avro/src/main/java/tools/jackson/dataformat/avro/AvroMapper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ public AvroFactory tokenStreamFactory() {
205205
return (AvroFactory) _streamFactory;
206206
}
207207

208+
/*
209+
/**********************************************************
210+
/* Format-specific
211+
/**********************************************************
212+
*/
213+
214+
public boolean isEnabled(AvroReadFeature f) {
215+
return _deserializationConfig.hasFormatFeature(f);
216+
}
217+
218+
public boolean isEnabled(AvroWriteFeature f) {
219+
return _serializationConfig.hasFormatFeature(f);
220+
}
221+
208222
/*
209223
/**********************************************************************
210224
/* Schema introspection

avro/src/test/java/tools/jackson/dataformat/avro/MapperConfigTest.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.ByteArrayOutputStream;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import tools.jackson.core.FormatSchema;
68
import tools.jackson.core.StreamReadCapability;
79
import tools.jackson.core.StreamWriteFeature;
@@ -28,6 +30,7 @@ public String getSchemaType() {
2830
/**********************************************************************
2931
*/
3032

33+
@Test
3134
public void testFactoryDefaults() throws Exception
3235
{
3336
assertTrue(MAPPER.tokenStreamFactory().isEnabled(AvroReadFeature.AVRO_BUFFERING));
@@ -38,25 +41,29 @@ public void testFactoryDefaults() throws Exception
3841
assertFalse(MAPPER.tokenStreamFactory().canUseSchema(BOGUS_SCHEMA));
3942
}
4043

44+
@Test
4145
public void testParserDefaults() throws Exception
4246
{
43-
AvroParser p = (AvroParser) MAPPER.createParser(new byte[0]);
44-
assertTrue(p.isEnabled(AvroReadFeature.AVRO_BUFFERING));
45-
p.close();
47+
try (AvroParser p = (AvroParser) MAPPER.createParser(new byte[0])) {
48+
assertTrue(p.isEnabled(AvroReadFeature.AVRO_BUFFERING));
49+
}
4650

4751
AvroMapper mapper = AvroMapper.builder()
4852
.disable(AvroReadFeature.AVRO_BUFFERING)
4953
.build();
50-
p = (AvroParser) mapper.createParser(new byte[0]);
51-
assertFalse(p.isEnabled(AvroReadFeature.AVRO_BUFFERING));
52-
53-
// 15-Jan-2021, tatu: 2.14 added this setting, not enabled in
54-
// default set
55-
assertTrue(p.streamReadCapabilities().isEnabled(StreamReadCapability.EXACT_FLOATS));
54+
try (AvroParser p = (AvroParser) mapper.createParser(new byte[0])) {
55+
assertFalse(p.isEnabled(AvroReadFeature.AVRO_BUFFERING));
56+
57+
// 15-Jan-2021, tatu: 2.14 added this setting, not enabled in
58+
// default set
59+
assertTrue(p.streamReadCapabilities().isEnabled(StreamReadCapability.EXACT_FLOATS));
60+
}
5661

57-
p.close();
58-
}
62+
// [dataformats-binary#619]
63+
assertTrue(MAPPER.isEnabled(AvroReadFeature.AVRO_BUFFERING));
64+
}
5965

66+
@Test
6067
public void testGeneratorDefaults() throws Exception
6168
{
6269
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
@@ -76,6 +83,9 @@ public void testGeneratorDefaults() throws Exception
7683
.createGenerator(bytes);
7784
assertFalse(g.isEnabled(AvroWriteFeature.AVRO_BUFFERING));
7885
g.close();
86+
87+
// [dataformats-binary#619]
88+
assertFalse(MAPPER.isEnabled(AvroWriteFeature.AVRO_FILE_OUTPUT));
7989
}
8090

8191
/*
@@ -84,6 +94,7 @@ public void testGeneratorDefaults() throws Exception
8494
/**********************************************************************
8595
*/
8696

97+
@Test
8798
public void testDefaultSettingsWithAvroMapper()
8899
{
89100
AvroMapper mapper = new AvroMapper();

release-notes/CREDITS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ Fawzi Essam (@iifawzi)
1818
* Contribited #591: Change `CBOR` Features defaults for 3.0
1919
(3.0.0)
2020

21+
Andy Wilkinson (@wilkinsona)
22+
23+
* Requested #619: (avro, cbor) Add `isEnabled()` methods for format-specific features (like
24+
`CBORReadFeature` and `CBORWriteFeature`) to mappers
25+
(3.1.0)

release-notes/VERSION

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ implementations)
1414
=== Releases ===
1515
------------------------------------------------------------------------
1616

17+
3.1.0 (not yet released)
18+
19+
#619: (avro, cbor) Add `isEnabled()` methods for format-specific features (like
20+
`CBORReadFeature` and `CBORWriteFeature`) to mappers
21+
(requested by Andy W)
22+
1723
3.0.1 (21-Oct-2025)
1824

1925
No changes since 3.0.0

0 commit comments

Comments
 (0)