Him188 / yamlkt

Multiplatform YAML parser & serializer for kotlinx.serialization written in pure Kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when a string value include ":"

sgpublic opened this issue · comments

This is the minimal code that triggers the problem:

@Serializable
data class ReverseWebSocket(
    @SerialName("url")
    override val url: String? = null,
)

YamlGlobal.decodeFromString(
    OneBotV11Connection.ReverseWebSocket.serializer(),
    YamlGlobal.decodeFromString(
        YamlMap.serializer(),
        """
        detail:
          url: "ws://xxxxxx:5703"
    """.trimIndent()
    )["detail"].toString()
)

My purpose is actually to convert YamlMap into the object I need. kotlinx-serialization-json provides methods from JsonElement to objects, but yamlkt does not seem to...

I change the code to this, then problem solved:

        @Serializable
        data class ReverseWebSocket(
            @SerialName("url")
            override val url: String? = null,
        )

        YamlGlobal.decodeFromString(
            OneBotV11Connection.ReverseWebSocket.serializer(),
            YamlGlobal.encodeToString(
                YamlGlobal.decodeFromString(
                    YamlMap.serializer(),
                    """
                detail:
                  url: "ws://xxxxxx:5703"
            """.trimIndent()
                )["detail"]
            )
        )
commented

Yes, there is currently no support for converting YamlMap to a serializable object. I also did the same workaround as yours.