-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More configurable TOML serialization #254
Comments
Good questions. Streaming writer can still buffer all of content and only emit things at the end (Properties backend does this), but whether that makes sense is an open question. I suspect that users will be asking for this in one particular case, for what that is worth: when modifying an existing TOML document. I agree that while annotations might be nice way, they cannot be accessed at streaming backend and would need to be somehow passed by databind. I have thought about this a bit wrt YAML output: there are various styles for textual content (no less than... five variations); no good ideas yet on how those should be passed. In case of YAML, custom One possibility, I think, would be an option that would force use of Tables but also assume strict ordering -- such that if closed table is "re-written", it'd throw exception. This could work in read-modify-write cycle where ordering is preserved (f.ex via |
hope to support table |
PRs welcome! |
tables and nested tables is one of the basics |
@sysmat Yes, as I said, PRs welcome. Arguing about usefulness of something does little to implement said feature. |
What is the status of this? I started trying to use jackson toml support and when I write presently it seems to output things in format similar to the above mentioned like
But was expecting the later
So is the ability to add a "table" (or whatever the toml nomenclature is - still new to it) not available in Jackson and is it related to this? |
Would adding some sort of annotation be a way forward? Say a @ Table(header="abc") which could be applied to a given java class? Although I suppose if multiple "Table" were added, that might have to be applied to each attribute to allow given object to group related items into the same or different sections. |
Challenge with format-specific annotations is that they cannot be supported by But it is also possible that no annotations were needed and it is just a question of making use of existing naming conventions and re-construct output. This is what "Properties" backend does. So I think it may be just that output side was left at minimum support level, not due to specific limitations. |
a good first step would be to support it in the generator, if anyone is interested in writing a pr. it's not on my roadmap atm. |
When working with JPA there are annotations to identify tables, columns, ids, etc. , With xml annotations in JAXB there are annotations like xml root, xml elements, and xml attributes. Would either of these be examples to build off of for possible annotation development here? |
What I am trying to say, as is @yawkat, is that the output side of TOML needs work even before considering need for new annotations. As to JAXB, it is XML-specific so not really (although Jackson has some compatibility support); JPA is DB-specific so I don't think so. But the original description of the issue is relevant: first things first, output formatting basically does not exist wrt sections. It would be possible to add that with default logic, and if necessary, then consider other annotations. |
Right now, the toml serializer generates only top level properties, and inline tables where necessary (i.e. where arrays are used):
There are special cases where we could generate normal toml tables. The example above can be expressed as:
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:
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
andwriteStartArray
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 towriteStartObject
, though this seems like misuse of that parameter, so not a good idea.The text was updated successfully, but these errors were encountered: