Skip to content

Commit b32fff1

Browse files
authored
Fix #581: add Mapper.isEnabled() (#582)
1 parent 0f42ae7 commit b32fff1

File tree

10 files changed

+110
-6
lines changed

10 files changed

+110
-6
lines changed

csv/src/main/java/tools/jackson/dataformat/csv/CsvMapper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,20 @@ public CsvFactory tokenStreamFactory() {
226226
return (CsvFactory) _streamFactory;
227227
}
228228

229+
/*
230+
/**********************************************************************
231+
/* Format-specific
232+
/**********************************************************************
233+
*/
234+
235+
public boolean isEnabled(CsvReadFeature f) {
236+
return _deserializationConfig.hasFormatFeature(f);
237+
}
238+
239+
public boolean isEnabled(CsvWriteFeature f) {
240+
return _serializationConfig.hasFormatFeature(f);
241+
}
242+
229243
/*
230244
/**********************************************************************
231245
/* Additional ObjectReader factory methods

csv/src/test/java/tools/jackson/dataformat/csv/CSVFactoryFeaturesTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,12 @@ public void testFactoryBuilderFastBigNumberFeature() throws Exception
102102
assertFalse(parser.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
103103
assertTrue(parser.isEnabled(StreamReadFeature.USE_FAST_DOUBLE_PARSER));
104104
}
105+
106+
// for [dataformats-text#581]
107+
@Test
108+
void testFormatFeatureDefaults() {
109+
CsvMapper mapper = CsvMapper.shared();
110+
assertFalse(mapper.isEnabled(CsvReadFeature.ALLOW_COMMENTS));
111+
assertFalse(mapper.isEnabled(CsvWriteFeature.ALWAYS_QUOTE_EMPTY_STRINGS));
112+
}
105113
}

release-notes/VERSION

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

17+
3.1.0 (not yet released)
18+
19+
#581: (csv, toml, yaml) Add `isEnabled()` methods for format-specific
20+
features to mappers
21+
1722
3.0.1 (21-Oct-2025)
1823

1924
No changes since 3.0.0

toml/src/main/java/tools/jackson/dataformat/toml/TomlMapper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ public TomlFactory tokenStreamFactory() {
184184
return (TomlFactory) _streamFactory;
185185
}
186186

187+
/*
188+
/**********************************************************************
189+
/* Format-specific
190+
/**********************************************************************
191+
*/
192+
193+
public boolean isEnabled(TomlReadFeature f) {
194+
return _deserializationConfig.hasFormatFeature(f);
195+
}
196+
197+
public boolean isEnabled(TomlWriteFeature f) {
198+
return _serializationConfig.hasFormatFeature(f);
199+
}
200+
187201
/*
188202
/**********************************************************************
189203
/* Helper class(es)

toml/src/main/java/tools/jackson/dataformat/toml/TomlReadFeature.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public enum TomlReadFeature
1515
* <p>
1616
* When this option is set, these time types will be parsed to their proper {@code java.time} counterparts and
1717
* appear as {@link tools.jackson.core.JsonToken#VALUE_EMBEDDED_OBJECT} tokens.
18+
*<p>
19+
* Feature is disabled by default.
1820
*/
1921
PARSE_JAVA_TIME(false);
2022

toml/src/main/java/tools/jackson/dataformat/toml/TomlWriteFeature.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public enum TomlWriteFeature implements FormatFeature
1313
* {@link JsonGenerator#writeNull()} by default.
1414
* <p>
1515
* When this option is set, any attempt to write a null value will error instead.
16+
*<p>
17+
* Feature is disabled by default.
1618
*/
1719
FAIL_ON_NULL_WRITE(false);
1820

toml/src/test/java/tools/jackson/dataformat/toml/TomlMapperTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import static org.junit.jupiter.api.Assertions.*;
1818

19-
public class TomlMapperTest extends TomlMapperTestBase {
20-
19+
public class TomlMapperTest extends TomlMapperTestBase
20+
{
2121
private static final String TEST_STRING = "foo = 'bar'\n[nested]\nfoo = 4";
2222
private static final TestClass TEST_OBJECT;
2323

@@ -199,4 +199,12 @@ public void nullDisable() {
199199
.build().writeValueAsString(cf));
200200
});
201201
}
202+
203+
// for [dataformats-text#581]
204+
@Test
205+
void testFormatFeatureDefaults() {
206+
TomlMapper mapper = TomlMapper.shared();
207+
assertFalse(mapper.isEnabled(TomlReadFeature.PARSE_JAVA_TIME));
208+
assertFalse(mapper.isEnabled(TomlWriteFeature.FAIL_ON_NULL_WRITE));
209+
}
202210
}

yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLMapper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ public final YAMLFactory tokenStreamFactory() {
197197
return (YAMLFactory) _streamFactory;
198198
}
199199

200+
/*
201+
/**********************************************************************
202+
/* Format-specific
203+
/**********************************************************************
204+
*/
205+
206+
public boolean isEnabled(YAMLReadFeature f) {
207+
return _deserializationConfig.hasFormatFeature(f);
208+
}
209+
210+
public boolean isEnabled(YAMLWriteFeature f) {
211+
return _serializationConfig.hasFormatFeature(f);
212+
}
213+
200214
/*
201215
/**********************************************************
202216
/* Helper class(es)

yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLWriteFeature.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,28 @@ public enum YAMLWriteFeature implements FormatFeature
1212
/**
1313
* Whether we are to write an explicit document start marker ("---")
1414
* or not.
15+
*<p>
16+
* Feature is enabled by default.
1517
*/
1618
WRITE_DOC_START_MARKER(true),
1719

1820
/**
1921
* Whether to use YAML native Object Id construct for indicating type (true);
2022
* or "generic" Object Id mechanism (false). Former works better for systems that
21-
* are YAML-centric; latter may be better choice for interoperability, when
23+
* are YAML-centric; latter may be better choice for inter-operability, when
2224
* converting between formats or accepting other formats.
25+
*<p>
26+
* Feature is enabled by default.
2327
*/
2428
USE_NATIVE_OBJECT_ID(true),
2529

2630
/**
2731
* Whether to use YAML native Type Id construct for indicating type (true);
2832
* or "generic" type property (false). Former works better for systems that
29-
* are YAML-centric; latter may be better choice for interoperability, when
33+
* are YAML-centric; latter may be better choice for inter-operability, when
3034
* converting between formats or accepting other formats.
35+
*<p>
36+
* Feature is enabled by default.
3137
*/
3238
USE_NATIVE_TYPE_ID(true),
3339

@@ -36,6 +42,8 @@ public enum YAMLWriteFeature implements FormatFeature
3642
* <p>
3743
* Ignored if you provide your own {@code DumperOptions}.
3844
* </p>
45+
*<p>
46+
* Feature is disabled by default.
3947
*/
4048
CANONICAL_OUTPUT(false),
4149

@@ -48,6 +56,8 @@ public enum YAMLWriteFeature implements FormatFeature
4856
* <p>
4957
* Ignored if you provide your own {@code DumperOptions}.
5058
* </p>
59+
*<p>
60+
* Feature is enabled by default.
5161
*/
5262
SPLIT_LINES(true),
5363

@@ -59,6 +69,8 @@ public enum YAMLWriteFeature implements FormatFeature
5969
* limited to printable characters according to the rules of
6070
* <a href="http://www.yaml.org/spec/1.2/spec.html#style/block/literal">literal block style</a>.
6171
* </p>
72+
*<p>
73+
* Feature is disabled by default.
6274
*/
6375
MINIMIZE_QUOTES(false),
6476

@@ -70,6 +82,8 @@ public enum YAMLWriteFeature implements FormatFeature
7082
* limited to printable characters according to the rules of
7183
* <a href="http://www.yaml.org/spec/1.2/spec.html#style/block/literal">literal block style</a>.
7284
* </p>
85+
*<p>
86+
* Feature is disabled by default.
7387
*/
7488
ALWAYS_QUOTE_NUMBERS_AS_STRINGS(false),
7589

@@ -81,6 +95,8 @@ public enum YAMLWriteFeature implements FormatFeature
8195
* The content of such strings is limited to printable characters according to the rules of
8296
* <a href="http://www.yaml.org/spec/1.2/spec.html#style/block/literal">literal block style</a>.
8397
* </p>
98+
*<p>
99+
* Feature is disabled by default.
84100
*/
85101
LITERAL_BLOCK_STYLE(false),
86102

@@ -93,7 +109,8 @@ public enum YAMLWriteFeature implements FormatFeature
93109
* <p>
94110
* Ignored if you provide your own {@code DumperOptions}.
95111
* </p>
96-
*
112+
*<p>
113+
* Feature is disabled by default.
97114
*/
98115
INDENT_ARRAYS(false),
99116

@@ -106,7 +123,8 @@ public enum YAMLWriteFeature implements FormatFeature
106123
* <p>
107124
* Ignored if you provide your own {@code DumperOptions}.
108125
* </p>
109-
*
126+
*<p>
127+
* Feature is disabled by default.
110128
*/
111129
INDENT_ARRAYS_WITH_INDICATOR(false),
112130

@@ -118,6 +136,8 @@ public enum YAMLWriteFeature implements FormatFeature
118136
* <p>
119137
* Ignored if you provide your own {@code DumperOptions}.
120138
* </p>
139+
*<p>
140+
* Feature is disabled by default.
121141
*/
122142
ALLOW_LONG_KEYS(false),
123143
;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package tools.jackson.dataformat.yaml;
2+
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
public class YAMLMapperTest extends ModuleTestBase
9+
{
10+
// for [dataformats-text#581]
11+
@Test
12+
void testFormatFeatureDefaults() {
13+
YAMLMapper mapper = YAMLMapper.shared();
14+
assertTrue(mapper.isEnabled(YAMLReadFeature.EMPTY_STRING_AS_NULL));
15+
assertFalse(mapper.isEnabled(YAMLWriteFeature.CANONICAL_OUTPUT));
16+
}
17+
}

0 commit comments

Comments
 (0)