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

Hcon: error while trying to decode MAP #1046

Closed
SchweinchenFuntik opened this issue Sep 7, 2020 · 0 comments
Closed

Hcon: error while trying to decode MAP #1046

SchweinchenFuntik opened this issue Sep 7, 2020 · 0 comments
Assignees
Milestone

Comments

@SchweinchenFuntik
Copy link

SchweinchenFuntik commented Sep 7, 2020

Describe the bug

bug.conf

value1 {
    name = "name1",
    dir = "dir1"
    fileExtension = ".xlsx"
}

value2 {
    name = "name2",
    dir = "dir2"
    fileExtension = ".xlsx"
}

value3 {
    name = "name3",
    dir = "dir3"
    fileExtension = ".xlsx"
}

code

@Serializable
data class TestConfig(
    val name: String,
    val dir: String = "",
    val fileExtension: String = ".xlsx",
)

@ExperimentalSerializationApi
fun main() {
    val bugConfig = Files.newBufferedReader(Path.of("./bug.conf")).use(ConfigFactory::parseReader)
    val bugMap = Server.hoconParser.decodeFromConfig<Map<String, TestConfig>>(bugConfig)
}

Exception

Exception in thread "main" java.util.NoSuchElementException: List is empty.
	at kotlin.collections.CollectionsKt___CollectionsKt.last(_Collections.kt:380)
	at kotlinx.serialization.internal.TaggedDecoder.getCurrentTag(Tagged.kt:308)
	at kotlinx.serialization.hocon.Hocon$ConfigReader.beginStructure(Hocon.kt:138)
	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:243)
	at kotlinx.serialization.internal.TaggedDecoder.decodeSerializableValue(Tagged.kt:179)
	at kotlinx.serialization.hocon.Hocon.decodeFromConfig(Hocon.kt:34)
	at TestKt.main(test.kt:194)
	at TestKt.main(test.kt)

error in code https://github.com/Kotlin/kotlinx.serialization/blob/master/formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/Hocon.kt#L138:

descriptor.kind == StructureKind.MAP -> MapConfigReader(conf.getObject(currentTag)) // currentTag NULL, tagStack: size 0

Environment

  • Kotlin version: 1.4.0
  • Library version: 1.0.0-RC
  • Kotlin platforms: JVM
  • Gradle version: 6.6.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants