yamlkt icon indicating copy to clipboard operation
yamlkt copied to clipboard

API doc is not in sync with the usage

Open rizsotto opened this issue 4 years ago • 5 comments

The API doc is suggest to use Yaml.parse method, which is not exists in the latest version I'm using.

I'm trying to parse a string into a specific type. Yaml.decodeFromString(MyType.serializer(), payload) is what I'm using. It works, but Intellij-IDEA is warning about Cannot access class 'kotlinx.serialization.DeserializationStrategy'. Check your module classpath for missing or conflicting dependencies.

plugins {
    kotlin("jvm") version "1.5.30"
    kotlin("plugin.serialization") version "1.5.30"
}
dependencies {
    implementation("net.mamoe.yamlkt:yamlkt:0.10.2")
}

Please advice, what is the correct usage of the library?

rizsotto avatar Sep 14 '21 01:09 rizsotto

Hi, see the dependent on the versions table yamlkt 0.10.2 needs only kotlin 1.5.20 and kotlinx-serialization 1.2.1. Use correct versions and try this:

val yaml = Yaml()
yaml.decodeFromString(MyType.serializer(), payload)

Works for me perfectly.

YokiToki avatar Sep 14 '21 04:09 YokiToki

Thanks @YokiToki , yes it works even with the 1.5.30 version... But my concern is mainly about the API doc is not suggesting what you've just recommended here.

rizsotto avatar Sep 14 '21 04:09 rizsotto

This is probably an IDE bug introduced in Kotlin 1.5.30. The compiler is still compiling fine while IDE reports such errors.

Him188 avatar Sep 14 '21 04:09 Him188

https://github.com/Him188/yamlkt/blob/master/yamlkt/src/commonMain/kotlin/net.mamoe.yamlkt/Yaml.kt#L26 https://github.com/Him188/yamlkt/blob/master/README.md#learn-to-use

^ These are the documentation I was referring to. Both suggest to use Yaml.parse(...) instead of the Yaml.decodeFromString(...). Do you think it would better to update them?

rizsotto avatar Sep 15 '21 08:09 rizsotto

@rizsotto Yes, I missed them during migration from serialization 0.10 to 0.20. Thank you.

Him188 avatar Sep 15 '21 20:09 Him188