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

How to deserialize TomlNode? #280

Open
Xirado opened this issue Sep 23, 2024 · 5 comments
Open

How to deserialize TomlNode? #280

Xirado opened this issue Sep 23, 2024 · 5 comments

Comments

@Xirado
Copy link

Xirado commented Sep 23, 2024

I need to dynamically traverse a toml file since i cannot deserialize the whole thing, but have not found a way to deserialize a TomlNode into a kotlinx Serializable class. Is it possible? If not, i think adding this functionality would be beneficial

@orchestr7
Copy link
Owner

I need to dynamically traverse a toml file since i cannot deserialize the whole thing, but have not found a way to deserialize a TomlNode into a kotlinx Serializable class. Is it possible? If not, i think adding this functionality would be beneficial

Hey! Yes, we have a partial serialization. It is very easy

@orchestr7
Copy link
Owner

orchestr7 commented Sep 25, 2024

I think this is your scenario. Check this part in the readmeimage

@Xirado
Copy link
Author

Xirado commented Sep 25, 2024

I think this is your scenario. Check this part in the readmeimage

Yes, i read about this, but shouldn't there be a more efficient way? Every call will cause the whole file to be parsed again, which is very inefficient, TomlTable already has all the information, so i think there should be a way to deserialize that aswell since it only requires reading the file once

@akuleshov7
Copy link

akuleshov7 commented Sep 26, 2024

Yes, i read about this, but shouldn't there be a more efficient way? Every call will cause the whole file to be parsed again, which is very inefficient, TomlTable already has all the information, so i think there should be a way to deserialize that aswell since it only requires reading the file once

Hm, may be I am getting this wrong, but if your file is changing dynamically and you re-read it again and again, then there anyway will be same parsing.

May be you can give some small example of the input and API, so we can implement it?

@Xirado
Copy link
Author

Xirado commented Sep 26, 2024

Yes, i read about this, but shouldn't there be a more efficient way? Every call will cause the whole file to be parsed again, which is very inefficient, TomlTable already has all the information, so i think there should be a way to deserialize that aswell since it only requires reading the file once

Hm, may be I am getting this wrong, but if your file is changing dynamically and you re-read it again and again, then there anyway will be same parsing.

May be you can give some small example of the input and API, so we can implement it?

The file isn't changing, but i need to read the file as such

[a]
foo = "foo"
bar = "bar"

[b.a]
foo = "foo"
bar = "bar"

[b.b]
foo = "foo"
bar = "bar"

[x.y.z]
foo = "foo"
bar = "bar"

and then decode the file as such that i get Map<String, Foobar> where the String represents the path, so e.g. x.y.z

And i already have the correct TomlTables i want to convert to Foobar, it's just that ktoml offers no way to do this conversion directly without using partial deserialization which is highly inefficient if you invoke it multiple times which is required here

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

3 participants