question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

More configurable TOML serialization

See original GitHub issue

Right now, the toml serializer generates only top level properties, and inline tables where necessary (i.e. where arrays are used):

abc.foo = 1
abc.bar = 2
abc.xyz = [{foo = 1, bar = 2}]

There are special cases where we could generate normal toml tables. The example above can be expressed as:

[abc]
foo = 1
bar = 2

[[abc.xyz]]
foo = 1
bar = 2

This format will in many cases be more readable. However, there are problems with non-inline tables that prevent us from emitting them in a streaming generator:

  • Once a table is started, it is impossible to go back to the parent or root table. If an object has scalar properties that we only see after we started a subtable, we have a problem.
  • Array tables only work with arrays of objects. If an array is heterogeneous, but we’ve already started emitting it as an array table, we have a problem.

These problems can only be solved with knowledge of the tree being serialized, and perhaps even by influencing property order so that scalars always come first. However, because I expect serialization to toml to be fairly niche – it is a configuration format meant to be written by humans, after all – it is not worth adding machinery to databind to implement this.

Another question to consider: What even is the best representation of an object? A short inline object may be more readable than starting a new table that includes the entire path to that object.

A possible solution to this problem would be to add API to the TomlGenerator to specifically start a table. One approach would be to create overloads for writeStartObject and writeStartArray that allow forcing generation as a table. If data is then passed that cannot be represented as a table (the bullet points above), we would error. While we’re at it, could also allow emitting comments with additional methods.

We could also inspect annotations on the forValue passed to writeStartObject, though this seems like misuse of that parameter, so not a good idea.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Aug 15, 2022

PRs welcome!

0reactions
cowtowncodercommented, Nov 22, 2022

@sysmat Yes, as I said, PRs welcome. Arguing about usefulness of something does little to implement said feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

status-im/nim-toml-serialization - GitHub
Decode into Nim data types mixed with TomlValueRef to parse any valid TOML value. Using TomlValueRef can offer more flexibility but also require...
Read more >
Configure your JAVA program with TOML file - Medium
There are many general-purpose serialization formats available and they can represent complex data structures in an easily stored format.
Read more >
Python and TOML: New Best Friends - Real Python
TOML is a configuration file format that's becoming increasingly ... In this tutorial, you'll learn more about TOML and how you can use...
Read more >
tomland: Bidirectional TOML serialization - Kowainik
life-sync: this tool allows you to sync your configs across multiple machines. It stores all tracked files in its own TOML configuration file....
Read more >
Learn toml in Y Minutes
TOML stands for Tom's Obvious, Minimal Language. It is a data serialisation language designed to be a minimal configuration file format that's easy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found