ktoml
ktoml copied to clipboard
Fetch a primitive value with a TOML path, so I don't need to create my own classes
In TomlJ I can extract values without needing to create my own classes
[content]
version = "1.2.3"
import org.tomlj.Toml
val libs = Toml.parse(File("data.toml").toPath())
val externalVersion = libs.getString("content.version")
I'd like to be able to do this with Ktoml.
I tried to use partiallyDecodeFromString():
Toml.partiallyDecodeFromString(String.serializer(), File("data.toml").readText(), "content.version")
But I got an error:
> Cannot find table with name <content.version> in the toml input. Are you sure that this table exists in the input? Not able to decode this toml part.
Hm, and what’s about anonymous maps we released last time? @aSemy
Something like was requested here: https://github.com/akuleshov7/ktoml/issues/234
Does this help? https://github.com/akuleshov7/ktoml#qa
[a]
b = 42
c = "String"
[a.innerTable]
d = 5
[a.otherInnerTable]
d = "String"
// MyClass(a={b=42, c=String, innerTable={d=5}, otherInnerTable={d=String}})
@Serializable
data class MyClass(
val a: Map<String, Map<String, String>>
)