Comments (2)
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 {"foo": {"bar": 123}}
in JSON notation. While the two first cases are easy enough to handle - just annotate foo
with the type of dictionary it corresponds to - the third one is a problem. Handling cases like this would require replacing the current simple pretty-printing algorithm with some slow and convoluted hackery, and the annotations to support it would be pretty invasive to boot.
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?
from 4koma.
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 (X
) I want to change may be at different levels, such as:
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.
from 4koma.
Related Issues (20)
- Comments are not allowed to contain newlines HOT 2
- How to control whether to generate inline list/map or not? HOT 5
- TomlMapper chaining/delegation HOT 2
- How to encode and decode an enum class? Could you provide a simple example? HOT 1
- Data classes with private properties not handled by encoding HOT 2
- 4koma outputs invalid TOML for `key = [ "foo" ]` on top level
- Whether to consider support for Java Type parameters? HOT 1
- Serializer quoting keys with underscores
- Each error should be its own subtype
- Antlr? seriously :D HOT 3
- Toml Parse Error with seemingly valid .toml file HOT 3
- Add to the "Alternatives" table which libraries use reflection HOT 1
- Publish to maven central HOT 3
- Port to kotlin multiplatform HOT 2
- Surprising error message for missing quotes
- Warn or fail on unused keys in decoded TOML file HOT 1
- Target Java 8 Rather than 17 HOT 1
- Inconsistent encoding of empty nullable collections
- Entries like in Gradle version catalogs .toml file HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 4koma.