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

Can't parse simple toml with List #231

Open
chabapok opened this issue Jun 16, 2023 · 2 comments
Open

Can't parse simple toml with List #231

chabapok opened this issue Jun 16, 2023 · 2 comments

Comments

@chabapok
Copy link

I have the next code:

import com.akuleshov7.ktoml.Toml
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.serializer

@Serializable
data class Foo(val x: List<Bar>)

@Serializable
data class Bar(val v: Int)

fun main(){
    val foo = Foo(arrayListOf( Bar(42)))
    val s = Toml().encodeToString(foo)
    println(s)


    val fooDeserialized = Toml().decodeFromString<Foo>(serializer(), s)

}

So when i run this, it produce next toml:

[[x]]
    v = 42

And then, decoding throws error:

Exception in thread "main" com.akuleshov7.ktoml.exceptions.InternalDecodingException: Incorrect decoding state in the beginStructure() with [[x]] ([[x]])[x] It's an internal error - you can do nothing with it, please report it to https://github.com/akuleshov7/ktoml/
	at com.akuleshov7.ktoml.decoders.TomlMainDecoder.iterateOverStructure(TomlMainDecoder.kt:246)
	at com.akuleshov7.ktoml.decoders.TomlMainDecoder.beginStructure(TomlMainDecoder.kt:212)
	at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:29)
	at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43)
	at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:257)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:16)
	at com.akuleshov7.ktoml.decoders.TomlAbstractDecoder.decodeSerializableValue(TomlAbstractDecoder.kt:96)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70)
	at Foo$$serializer.deserialize(tomlProb.kt:6)
	at Foo$$serializer.deserialize(tomlProb.kt:6)
	at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:257)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:16)
	at com.akuleshov7.ktoml.decoders.TomlAbstractDecoder.decodeSerializableValue(TomlAbstractDecoder.kt:96)
	at com.akuleshov7.ktoml.decoders.TomlMainDecoder$Companion.decode(TomlMainDecoder.kt:276)
	at com.akuleshov7.ktoml.Toml.decodeFromString(Toml.kt:47)
	at TomlProbKt.main(tomlProb.kt:18)
	at TomlProbKt.main(tomlProb.kt)
@orchestr7
Copy link
Owner

orchestr7 commented Jun 16, 2023

Hello! Thank you for your report.
Thing that you are trying to decode looks to be not a simple array, it is an array of tables. Which is not supported.

Please note that primitive arrays/lists are actually supported:

val str = “””
[table]
   a = [1, 2, 3]
“””

@orchestr7
Copy link
Owner

#88

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