Giter Site home page Giter Site logo

Comments (22)

akuleshov7 avatar akuleshov7 commented on June 10, 2024

will be investigated this month

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

thank you for your report and sorry for a long delay!

from ktoml.

y9san9 avatar y9san9 commented on June 10, 2024

Still having the issue, is there any workaround? Really need to deserialize libs.versions.toml

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

@y9san9 sorry for a stupid question, what is the datastucture in toml reflects Maps? Cannot find a simple example.

Any string that you are trying to decode?

from ktoml.

y9san9 avatar y9san9 commented on June 10, 2024

Your class Toml produces from:

Toml.encodeToString(mapOf("library" to "1.0.0", "kotlin" to "2.0.0")) 

The following:

library = "1.0.0"
kotlin = "2.0.0"

And I want to decode that back, but cannot do that at the moment. All Toml spec is about to be converted to hash tables (probably that's something similar to hash maps)

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

Hm, but it's a little bit weird actually:

library = "1.0.0"
kotlin = "2.0.0"

is not a Map... It's a number of properties in Toml specification.

To store it to the map, I will need to guess the type somehow and understand that it is really a Map, but not a property, that user forgot to provide (due to his manual bug).

from ktoml.

y9san9 avatar y9san9 commented on June 10, 2024

So how could I deserialize that?

And also that:

coreKtx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }

All the solutions I found did that using Map

from ktoml.

y9san9 avatar y9san9 commented on June 10, 2024

(I don't know the exact names, I want to deserialize arbitrary amount of such rows)

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

So how could I deserialize that?

And also that:

coreKtx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }

All the solutions I found did that using Map

hm, let me look into the spec of TOML

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

So how could I deserialize that?

And also that:

coreKtx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }

All the solutions I found did that using Map

According to the spec, it's Inline Table https://toml.io/en/v1.0.0#inline-table and we should be able to decode it 🤔

from ktoml.

y9san9 avatar y9san9 commented on June 10, 2024

A list of inline tables? If so, that doesn't work either.

@Serializable
data class Libraries(
    val libraries: List<@TomlInlineTable Library>
) {
    @Serializable
    data class Library(val module: String, val version: String)
}

How do I get coreKtx with such setup?

from ktoml.

y9san9 avatar y9san9 commented on June 10, 2024

The intuitive approach: to add pair name -> inline table I used the Map type, which is also being encoded in such structure I needed, but is not being decoded back

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

A list of inline tables?

I think that this might help:
https://github.com/akuleshov7/ktoml#how-ktoml-works-examples

We actually had a test and an example for such structures:
gradle-libs-like-property = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }

your class:
    @SerialName("gradle-libs-like-property")
    val kotlinJvm: GradlePlugin

@Serializable
data class GradlePlugin(val id: String, val version: Version)

But actually I do not like the behaviour when we create a map on serialization and then have ambiguity on the deserialisation with the same class. I understood the problem, but do Inline Tables will help you now in your particular case?

from ktoml.

y9san9 avatar y9san9 commented on June 10, 2024

Sorry, as I mentioned earlier that I don't know what names of the libraries will be. I want to parse them and only after that I could tell the names.

from ktoml.

y9san9 avatar y9san9 commented on June 10, 2024

In Json when you don't know class layout you would also use Map<String, JsonElement>

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

Sorry, as I mentioned earlier that I don't know what names of the libraries will be. I want to parse them and only after that I could tell the names.

Got it, so you need to parse properties without explicit naming, and you need to decode it to some map of strings. I do not have an idea of how to support it now, as it is violating TOML spec, but I will think...

from ktoml.

y9san9 avatar y9san9 commented on June 10, 2024

Why is it violating TOML specs? It's how Version Catalogs work :)

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

Why is it violating TOML specs? It's how Version Catalogs work :)

Yes, I mean that the idea of TOML is that you know the names of the properties. That's why this structure:

a = 1

is a NAMED key-value property https://toml.io/en/v1.0.0#keyvalue-pair

It will be a different story to decode the following code:

a = 1
b = 2

to a Map("a" to "1", "b" to "2"), because the original idea is about named keys with typed values:

val a: Int
val b: Int

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

BUT! Ktoml itself has multiple extensions to the original idea of TOML, so probably we can think of something we can do here. Especially when we encode these values to a Map. Need to think...

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

Initial implementation is done for simple map: #246 (phase 1)
@jakubgwozdz @y9san9

Phase 2 with nested tables: WIP

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

Nested Maps (nested tables) done in #252

from ktoml.

akuleshov7 avatar akuleshov7 commented on June 10, 2024

Released in 0.5.1

from ktoml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.