Case 1 :-
Code:
public static void main(String[] args) {
TomlParseResult toml = null;
try {
Path source = Paths.get("D:/test/example.toml");
toml = Toml.parse(source);
TomlArray array = toml.getTable("array").getArray("key1");
System.out.println("Count: " + array.size());
for (int i = 0; i < array.size(); i++) {
System.out.println("Value " + (i+1) + ": " + array.get(i));
}
} catch (Exception e) {
e.printStackTrace();
}
}
Data:
[array]
key1 = [1979-05-27T00:32:00.999999-07:00, 1979-05-28T00:32:00.999999-07:00, 1979-05-31T07:32:00]
Result:
Count: 2
Value 1: 1979-05-27T00:32:00.999999-07:00
Value 2: 1979-05-28T00:32:00.999999-07:00
Debug shows error: "Unexpected '1979-05-31T07', expected ] or a newline" But no exception thrown.
Expected: Successful Execution
Got the below stacktrace:
java.lang.IllegalArgumentException: Error occured during parsing: Unexpected ']', expected ], a comma, or a newline
at org.tomlj.Parser.parse(Parser.java:41)
at org.tomlj.Toml.parse(Toml.java:80)
at org.tomlj.Toml.parse(Toml.java:67)
at Main.main(Main.java:16)
Caused by: Unexpected ']', expected ], a comma, or a newline (line 188, column 102)
at org.tomlj.AccumulatingErrorListener.reportError(AccumulatingErrorListener.java:67)
at org.tomlj.AccumulatingErrorListener.syntaxError(AccumulatingErrorListener.java:54)
at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41)
at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:544)
at org.antlr.v4.runtime.DefaultErrorStrategy.reportUnwantedToken(DefaultErrorStrategy.java:377)
at org.antlr.v4.runtime.DefaultErrorStrategy.singleTokenDeletion(DefaultErrorStrategy.java:548)
at org.antlr.v4.runtime.DefaultErrorStrategy.sync(DefaultErrorStrategy.java:266)
at org.tomlj.internal.TomlParser.array(TomlParser.java:3011)
at org.tomlj.internal.TomlParser.val(TomlParser.java:754)
at org.tomlj.internal.TomlParser.keyval(TomlParser.java:409)
at org.tomlj.internal.TomlParser.expression(TomlParser.java:298)
at org.tomlj.internal.TomlParser.toml(TomlParser.java:219)
at org.tomlj.Parser.parse(Parser.java:37)
... 3 more
Case 2 :- - UPDATE: I understood how error handling is done. Consider Case 2 as SOLVED!
Code: Same as Case 1
Data:
[array]
key1 = [s1979-05-27T00:32:00.999999-07:00, s1979-05-28T00:32:00.999999-07:00, s1979-05-31T07:32:00]
Result:
Count: 1
Value 1: 1979-05-27T00:32:00.999999-07:00
Expected: ParserException
Case 3 :-
Code:
public static void main(String[] args) {
TomlParseResult toml = null;
try {
Path source = Paths.get("D:/test/example-v0.4.0.toml");
toml = Toml.parse(source);
TomlArray array = toml.getTable("array").getArray("key1");
System.out.println("Count: " + array.size());
System.out.println(array.containsLongs());
System.out.println(array.containsStrings());
System.out.println(array.containsBooleans());
System.out.println(array.containsOffsetDateTimes());
System.out.println(array.containsLocalDateTimes());
System.out.println(array.containsLocalDates());
System.out.println(array.containsLocalTimes());
System.out.println(array.containsDoubles());
for (int i = 0; i < array.size(); i++) {
System.out.println("Value " + (i+1) + ": " + array.get(i));// + " -> " + TomlType.typeNameFor(array.get(i)));
}
} catch (Exception e) {
e.printStackTrace();
}
}
Data:
[array]
key1 = [s1979-0x5-27T00:32:00.999999-07:00, s1979-05-28T00:32:00.999999-07:00, s1979-05-31T07:32:00]
Result:
Count: 0
true
true
true
true
true
true
true
true
Expected: ParserException. Boolean values to be false?
Can you please have a look?
Also, #3 was raised by me. I tweaked the source a bit and they seem to work as expected.
Can you please have a look at #3 and make/merge necessary changes?
Again, thank you for this lib! I'm not a java developer, nor an expert in Java. Found TOML and decided to play with it. If you get time, please take the below requests into consideration:
Requests:
(i) The reason I asked for maintaining sequence while creating JSON - want to implement JSON schema validation on this. In future, may be TOLS would be reality to validate the structure!
(ii) How about a toToml() similar to toJson()? Converts JSON to TOML.
Hope to see v1.0 implemented as well ๐