-
Notifications
You must be signed in to change notification settings - Fork 13
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve original formatting when serializing #26
Comments
I think this would be doable for 90% of cases without too much work. The last 10% would be significantly harder. Consider the following examples: [foo]
bar = 123 foo = {bar = 123} foo.bar = 123 All of these map to Would a best effort solution, which does the right thing as long as you only use the first two forms but converts the third form into the first during a roundtrip, still be useful? |
In my case, I have an end-user editable configuration file which may include custom formatting and comments. The file is read in full and decoded to data classes on startup. In some cases I want to persist changes to the configuration. Typicaly, I have one or a few specific value(s) that I want to change programmatically. The rest of the file should not be changed (i.e. preserving custom white space and comments). The value ( a = "X" [a]
b.c = "X" [a]
b = [ "X", "y", "z" ] [a]
b = [ { c = "X", d = "y" }, { e = "z" } ] As hinted at earlier, if it is simpler, for my use case it would be fine to say something like: tomlMapper.encodeInline(tomlFilePath, "a.b.c", newValue) In this case, the full file would not be decoded. Instead, it would be parsed only enough to identify the "bounds" of the existing value for that key in the file, and then replace that part of the file with the new value. |
Hi Anton! 馃憢馃檪
In my current use case, I have a user-edited toml file where I sometimes want to update a specific value programmatically. In this scenario, I would want to update the file without losing any comments or custom white space added by the user (except when directly affected by the change).
In the the most general form,
TomlValue.from(path).write(path)
would be a "no-op". If theTomlValue
is modified between reading and writing as little formatting should change as possible. As a more special case, I could imagine a special operation which writes a new value to a single specified key without decoding the full document. But that may not be in line with the current API.I understand that this may be a fundamental change and simply out of scope, but it doesn't hurt to ask, right? 馃榿
The text was updated successfully, but these errors were encountered: