Hi,
I want to use or library to deserialize Gradle's libs.versions.toml files into some object representation, apply modifications on those objects and serialize them back to files.
Here's a concrete example of what I'm doing:
TOML file:
[versions]
my-lib = "1.2.3"
[libraries]
my-lib = { group = "com.acme.foo", name = "my-lib", version.ref = "my-lib" }
So regarding the file contents, I only know that there will always be two regular tables (versions & libraries) and I know that the keys of the libraries table will always refer to an inline table, but I don't know the key names beforehand. They could match any name.
Decoding classes:
@Serializable
data class VersionsTOML(
val versions: MutableMap<String, String>,
val libraries: Map<String, Library> // Can I tell the serializer that Library is a nested inline table somehow?
)
@Serializable
data class Library(val group: String, val name: String, val version: Version)
@Serializable
data class Version(val ref: String)
Decoding the TOML file example shown above works like a charm, but this is actually the result if a serialize the decoded file contents back to a String again:
val tomlContent = """
[versions]
my-lib = "1.2.3"
[libraries]
my-lib = { group = "com.acme.foo", name = "my-lib", version.ref = "my-lib" }
""".trimIndent()
val config = Toml.decodeFromString<VersionsTOML>(tomlContent)
val configString = Toml.encodeToString(config)
println(configString)
That produces:
my-lib = "1.2.3"
[libraries]
[libraries.my-lib]
group = "com.acme.foo"
name = "my-lib"
[libraries.my-lib.version]
ref = "my-lib"
I think this might probably be related to #8. Please let me know in case there's anything I can do differently to make this work or you need anything else from me.
Thx for making this library happening,
Patrick
Hi,
I want to use or library to deserialize Gradle's
libs.versions.tomlfiles into some object representation, apply modifications on those objects and serialize them back to files.Here's a concrete example of what I'm doing:
TOML file:
So regarding the file contents, I only know that there will always be two regular tables (versions & libraries) and I know that the keys of the libraries table will always refer to an inline table, but I don't know the key names beforehand. They could match any name.
Decoding classes:
Decoding the TOML file example shown above works like a charm, but this is actually the result if a serialize the decoded file contents back to a String again:
That produces:
I think this might probably be related to #8. Please let me know in case there's anything I can do differently to make this work or you need anything else from me.
Thx for making this library happening,
Patrick