1

After a quick research, I found the following three libraries for parsing Toml files in java. toml4j tomlj jackson-dataformats-text

What I am looking for is a library that can parse toml files without a corresponding POJO class. While both toml4j, and tomlj can achieve that, they do not seem to be maintained.

jackson-dataformats-text on the other is actively maintained but I can not parse a toml file without the corresponding POJO class. Is there a way to create a dynamic class in java that I can use to parse any toml file?

Rami ZK
  • 510
  • 3
  • 13

1 Answers1

0

If you just need to read a TOML file without a POJO, FasterXML Jackson libraries are a great choice. The simplest method is to just read the content as a java.util.Map:

final var tomlMapper = new TomlMapper();
final var data = tomlMapper.readValue(new File("config.toml"), Map.class);

After that, the content of the file will be available in data.

If you need even lower level parsing, all formats supported by FasterXML Jackson can be read using the stream API. In case you need that, read about the stream API on the core module: FasterXML/jackson-core, just make sure you use the right factory class (TomlFactory instead of JsonFactory).