Comments (22)
will be investigated this month
from ktoml.
thank you for your report and sorry for a long delay!
from ktoml.
Still having the issue, is there any workaround? Really need to deserialize libs.versions.toml
from ktoml.
@y9san9 sorry for a stupid question, what is the datastucture in toml reflects Maps? Cannot find a simple example.
Any string that you are trying to decode?
from ktoml.
Your class Toml produces from:
Toml.encodeToString(mapOf("library" to "1.0.0", "kotlin" to "2.0.0"))
The following:
library = "1.0.0"
kotlin = "2.0.0"
And I want to decode that back, but cannot do that at the moment. All Toml spec is about to be converted to hash tables (probably that's something similar to hash maps)
from ktoml.
Hm, but it's a little bit weird actually:
library = "1.0.0"
kotlin = "2.0.0"
is not a Map... It's a number of properties in Toml specification.
To store it to the map, I will need to guess the type somehow and understand that it is really a Map, but not a property, that user forgot to provide (due to his manual bug).
from ktoml.
So how could I deserialize that?
And also that:
coreKtx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }
All the solutions I found did that using Map
from ktoml.
(I don't know the exact names, I want to deserialize arbitrary amount of such rows)
from ktoml.
So how could I deserialize that?
And also that:
coreKtx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }All the solutions I found did that using Map
hm, let me look into the spec of TOML
from ktoml.
So how could I deserialize that?
And also that:
coreKtx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }All the solutions I found did that using Map
According to the spec, it's Inline Table
https://toml.io/en/v1.0.0#inline-table and we should be able to decode it 🤔
from ktoml.
A list of inline tables? If so, that doesn't work either.
@Serializable
data class Libraries(
val libraries: List<@TomlInlineTable Library>
) {
@Serializable
data class Library(val module: String, val version: String)
}
How do I get coreKtx
with such setup?
from ktoml.
The intuitive approach: to add pair name
-> inline table
I used the Map type, which is also being encoded in such structure I needed, but is not being decoded back
from ktoml.
A list of inline tables?
I think that this might help:
https://github.com/akuleshov7/ktoml#how-ktoml-works-examples
We actually had a test and an example for such structures:
gradle-libs-like-property = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
your class:
@SerialName("gradle-libs-like-property")
val kotlinJvm: GradlePlugin
@Serializable
data class GradlePlugin(val id: String, val version: Version)
But actually I do not like the behaviour when we create a map on serialization and then have ambiguity on the deserialisation with the same class. I understood the problem, but do Inline Tables will help you now in your particular case?
from ktoml.
Sorry, as I mentioned earlier that I don't know what names of the libraries will be. I want to parse them and only after that I could tell the names.
from ktoml.
In Json when you don't know class layout you would also use Map<String, JsonElement>
from ktoml.
Sorry, as I mentioned earlier that I don't know what names of the libraries will be. I want to parse them and only after that I could tell the names.
Got it, so you need to parse properties without explicit naming, and you need to decode it to some map of strings. I do not have an idea of how to support it now, as it is violating TOML spec, but I will think...
from ktoml.
Why is it violating TOML specs? It's how Version Catalogs work :)
from ktoml.
Why is it violating TOML specs? It's how Version Catalogs work :)
Yes, I mean that the idea of TOML is that you know the names of the properties. That's why this structure:
a = 1
is a NAMED key-value property https://toml.io/en/v1.0.0#keyvalue-pair
It will be a different story to decode the following code:
a = 1
b = 2
to a Map("a" to "1", "b" to "2"), because the original idea is about named keys with typed values:
val a: Int
val b: Int
from ktoml.
BUT! Ktoml itself has multiple extensions to the original idea of TOML, so probably we can think of something we can do here. Especially when we encode these values to a Map. Need to think...
from ktoml.
Initial implementation is done for simple map: #246 (phase 1)
@jakubgwozdz @y9san9
Phase 2 with nested tables: WIP
from ktoml.
Nested Maps (nested tables) done in #252
from ktoml.
Released in 0.5.1
from ktoml.
Related Issues (20)
- Post-release: update documentation
- For multiline strings need to trim all spaces before separators
- Latest release requires ktoml-source to be added when ktoml-file is used
- Regression in 0.5.0 in escaping back slashes in strings HOT 2
- TomlTable.write() throws NoSuchElementException if children is empty HOT 1
- Add extra logic for validating enum values
- Can't parse simple toml with List HOT 2
- Support for quoted keys and values with special symbols HOT 2
- Support for zero-item inline tables HOT 1
- Feature request: support value classes HOT 1
- Allow Missing Properties as a configuration option HOT 1
- Support new built-in types
- Why this library is not mentioned in official toml site? HOT 3
- encodeToString produces wrong indentation for case when there are nested List among the tree HOT 2
- How to deserialise Nested-Tables? HOT 1
- Fetch a primitive value with a TOML path, so I don't need to create my own classes HOT 3
- According to the TOML specification string values HOT 4
- Char encoding error HOT 2
- Linux arm64 HOT 3
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 ktoml.