Skip to content

Commit f366d3b

Browse files
committed
Remove ParserOptions class, replace with normal TomlReadFeature bit field
1 parent 51ed8ae commit f366d3b

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

toml/src/main/java/com/fasterxml/jackson/dataformat/toml/Parser.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ class Parser {
2121
private static final JsonNodeFactory factory = new JsonNodeFactoryImpl();
2222

2323
private final JacksonTomlParseException.ErrorContext errorContext;
24-
private final ParserOptions options;
24+
private final int options;
2525
private final Lexer lexer;
2626

2727
private TomlToken next;
2828

29-
private Parser(JacksonTomlParseException.ErrorContext errorContext, ParserOptions options, Reader reader) throws IOException {
29+
private Parser(JacksonTomlParseException.ErrorContext errorContext, int options, Reader reader) throws IOException {
3030
this.errorContext = errorContext;
3131
this.options = options;
3232
this.lexer = new Lexer(reader, errorContext);
3333
this.next = lexer.yylex();
3434
}
3535

36-
public static ObjectNode parse(JacksonTomlParseException.ErrorContext errorContext, ParserOptions options, Reader reader) throws IOException {
36+
public static ObjectNode parse(JacksonTomlParseException.ErrorContext errorContext, int options, Reader reader) throws IOException {
3737
return new Parser(errorContext, options, reader).parse();
3838
}
3939

@@ -191,7 +191,7 @@ private JsonNode parseDateTime(int nextState) throws IOException {
191191
text = text.substring(0, 10) + 'T' + text.substring(11);
192192
}
193193

194-
if (options.parseTemporalAsJavaTime) {
194+
if (TomlReadFeature.PARSE_JAVA_TIME.enabledIn(options)) {
195195
Temporal value;
196196
if (token == TomlToken.LOCAL_DATE) {
197197
value = LocalDate.parse(text);

toml/src/main/java/com/fasterxml/jackson/dataformat/toml/ParserOptions.java

-9
This file was deleted.

toml/src/main/java/com/fasterxml/jackson/dataformat/toml/TomlFactory.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,13 @@ protected Writer _createWriter(IOContext ioCtxt, OutputStream out, JsonEncoding
201201
private ObjectNode parse(ObjectReadContext readCtxt, IOContext ctxt, Reader r0) {
202202
JacksonTomlParseException.ErrorContext errorContext = new JacksonTomlParseException.ErrorContext(ctxt.sourceReference(), null);
203203
int readFeatures = readCtxt.getFormatReadFeatures(DEFAULT_TOML_PARSER_FEATURE_FLAGS);
204-
ParserOptions options = new ParserOptions(
205-
TomlReadFeature.PARSE_JAVA_TIME.enabledIn(readFeatures)
206-
);
207204
try {
208205
if (ctxt.isResourceManaged() || isEnabled(StreamReadFeature.AUTO_CLOSE_SOURCE)) {
209206
try (Reader r = r0) {
210-
return Parser.parse(errorContext, options, r);
207+
return Parser.parse(errorContext, readFeatures, r);
211208
}
212209
} else {
213-
return Parser.parse(errorContext, options, r0);
210+
return Parser.parse(errorContext, readFeatures, r0);
214211
}
215212
} catch (IOException e) {
216213
throw _wrapIOFailure(e);

toml/src/test/java/com/fasterxml/jackson/dataformat/toml/ParserTest.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
@SuppressWarnings("OctalInteger")
2424
public class ParserTest {
25-
private final ParserOptions testOptions = new ParserOptions(false);
2625
private final ObjectMapper jsonMapper = JsonMapper.builder()
2726
.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
2827
.enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS)
@@ -33,10 +32,10 @@ private ObjectNode json(@Language("json") String json) {
3332
}
3433

3534
private ObjectNode toml(@Language("toml") String toml) throws IOException {
36-
return toml(testOptions, toml);
35+
return toml(0, toml);
3736
}
3837

39-
private ObjectNode toml(ParserOptions opts, @Language("toml") String toml) throws IOException {
38+
private ObjectNode toml(int opts, @Language("toml") String toml) throws IOException {
4039
return Parser.parse(new JacksonTomlParseException.ErrorContext(null, null), opts, new StringReader(toml));
4140
}
4241

@@ -896,7 +895,7 @@ public void intTypes() throws IOException {
896895
.put("int1", 99)
897896
.put("int2", 4242424242L)
898897
.put("int3", new BigInteger("171717171717171717171717")),
899-
toml(new ParserOptions(false), "int1 = +99\n" +
898+
toml("int1 = +99\n" +
900899
"int2 = 4242424242\n" +
901900
"int3 = 171717171717171717171717")
902901
);
@@ -911,7 +910,7 @@ public void longBase() throws IOException {
911910
.put("hex3", 0xddead_beefL)
912911
.put("oct1", 01234567777777L)
913912
.put("bin1", 0b11010110101010101010101010101010101010L),
914-
toml(new ParserOptions(false), "hex1 = 0xdDEADBEEF\n" +
913+
toml("hex1 = 0xdDEADBEEF\n" +
915914
"hex2 = 0xddeadbeef\n" +
916915
"hex3 = 0xddead_beef\n" +
917916
"oct1 = 0o1234567777777\n" +
@@ -928,7 +927,7 @@ public void bigintBase() throws IOException {
928927
.put("hex3", new BigInteger("DDEADBEEFDDEADBEEF", 16))
929928
.put("oct1", new BigInteger("12345677777771234567777777", 8))
930929
.put("bin1", new BigInteger("1101011010101010101010101010101010101011010110101010101010101010101010101010", 2)),
931-
toml(new ParserOptions(false), "hex1 = 0xDDEADBEEFDDEADBEEF\n" +
930+
toml("hex1 = 0xDDEADBEEFDDEADBEEF\n" +
932931
"hex2 = 0xddeadbeefddeadbeef\n" +
933932
"hex3 = 0xddead_beefddead_beef\n" +
934933
"oct1 = 0o12345677777771234567777777\n" +
@@ -939,7 +938,7 @@ public void bigintBase() throws IOException {
939938
@Test
940939
public void javaTimeDeser() throws IOException {
941940
// this is the same test as above, except with explicit java.time deserialization
942-
ParserOptions options = new ParserOptions(true);
941+
int options = TomlReadFeature.PARSE_JAVA_TIME.getMask();
943942

944943
Assert.assertEquals(
945944
JsonNodeFactory.instance.objectNode()

0 commit comments

Comments
 (0)