Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch a primitive value with a TOML path, so I don't need to create my own classes #256

Open
aSemy opened this issue Jan 27, 2024 · 3 comments

Comments

@aSemy
Copy link
Collaborator

aSemy commented Jan 27, 2024

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.
@aSemy aSemy changed the title Fetch a primitive value with a path, so I don't need to create my own classes Fetch a primitive value with a TOML path, so I don't need to create my own classes Jan 27, 2024
@akuleshov7
Copy link
Owner

akuleshov7 commented Jan 29, 2024

Hm, and what’s about anonymous maps we released last time? @aSemy

@akuleshov7
Copy link
Owner

akuleshov7 commented Jan 29, 2024

Something like was requested here: #234

@akuleshov7
Copy link
Owner

akuleshov7 commented Jan 29, 2024

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>>
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants