Repository metrics
- Stars
- (561 stars)
- PR merge metrics
- (PR metrics pending)
Description
Give a TOML like:
[known]
foo = "bar"
[known.unknownA]
blah = "one"
[known.unknownB]
blah = "two"
I don't see a way to bind this while also still doing type validation on the known table and the unknown child table shapes (just not their keys).
I would want to bind it against a type defined something like this:
@Serializable
data class Config(
val known: Known,
@UnboundTables // Probably needs some marker annotation like this?
val unknowns: Map<String, KnownChild>,
)
@Serializable
data class Known(val foo: String)
@Serializable
data class KnownChild(val blah: String)
In the case where the child tables do not conform to the same shape, this should also be allowed:
@Serializable
data class Config(
val known: Known,
@UnboundTables // Probably needs some marker annotation like this?
val unknowns: Map<String, TomlTable>,
)
@Serializable
data class Known(val foo: String)
And finally, I have a real-world case which is mixing known table names and unknown table names in a single type. So the TOML looks like this:
[knownA]
foo = "bar"
[knownB]
foo = "baz"
[unknownA]
thing = "something"
other = "whatever"
[unknownB]
thing = "it's a thing"
other = "stuff"
Ideally I could somehow bind this against a type like:
@Serializable
data class Config(
val knownA: Known,
val knownB: Known,
@UnboundTables // Probably needs some marker annotation like this?
val unknowns: Map<String, Other>,
)
@Serializable
data class Known(val foo: String)
@Serializable
data class Other(val thing: String, val other: String)
I looked through the issues, documentation, and tests cases and didn't see anything that would suggest this is supported today. So far the only path forward I've seen is to go directly to TomlTable and do the entirety of the type binding myself.