esensar / kotlinx-serialization-msgpack

MsgPack support for kotlinx.serialization -- msgpack.org[kotlinx.serialization]
https://www.ensarsarajcic.com/kotlinx-serialization-msgpack/
MIT License
44 stars 9 forks source link

Bug: unable to serialize Map<String, Any> #96

Closed krisbitney closed 1 year ago

krisbitney commented 1 year ago

Version

Describe the bug I am trying to deserialize this map as Map<String, Any>

val env = mapOf(
    "provider" to listOf("https://ipfs.wrappers.io"),
    "fallbackProviders" to listOf("https://ipfs.io"),
    "retries" to mapOf("tryResolveUri" to 2, "getFile" to 2),
)

val encodedEnv = msgPackEncode(MsgPackDynamicSerializer, env)

I am getting the "End of Stream" exception thrown at line 31 of MsgPackDataBuffer.

See: https://github.com/esensar/kotlinx-serialization-msgpack/blob/main/serialization-msgpack/src/commonMain/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/stream/MsgPackDataBuffer.kt#L31

Traceback:

kotlin.Exception: End of stream
    at kotlin.Throwable#<init>(/opt/buildAgent/work/460cf706e11bbdb0/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:25)
    at kotlin.Exception#<init>(/opt/buildAgent/work/460cf706e11bbdb0/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23)
    at com.ensarsarajcic.kotlinx.serialization.msgpack.stream.MsgPackDataInputBuffer#requireNextByte(/Users/kris/IdeaProjects/esensar/kotlinx-serialization-msgpack/serialization-msgpack/src/commonMain/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/stream/MsgPackDataBuffer.kt:31)
    at com.ensarsarajcic.kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder#decodeCollectionSize(/Users/kris/IdeaProjects/esensar/kotlinx-serialization-msgpack/serialization-msgpack/src/commonMain/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/internal/MsgPackDecoder.kt:128)
    at com.ensarsarajcic.kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder#beginStructure(/Users/kris/IdeaProjects/esensar/kotlinx-serialization-msgpack/serialization-msgpack/src/commonMain/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/internal/MsgPackDecoder.kt:192)
    at eth.krisbitney.polywrap.uriResolvers.extendable.MaybeUriOrManifest.$serializer#deserialize(/Users/kris/IdeaProjects/krisbitney/polywrap-kt/src/commonMain/kotlin/eth.krisbitney.polywrap/uriResolvers/extendable/MaybeUriOrManifest.kt:1)
    at kotlinx.serialization.encoding.Decoder#decodeSerializableValue(/opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/encoding/Decoding.kt:257)
    at com.ensarsarajcic.kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder#decodeSerializableValue(/Users/kris/IdeaProjects/esensar/kotlinx-serialization-msgpack/serialization-msgpack/src/commonMain/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/internal/MsgPackDecoder.kt:182)
    at com.ensarsarajcic.kotlinx.serialization.msgpack.internal.MsgPackDecoder#decodeSerializableValue(/Users/kris/IdeaProjects/esensar/kotlinx-serialization-msgpack/serialization-msgpack/src/commonMain/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/internal/MsgPackDecoder.kt:1)
    at com.ensarsarajcic.kotlinx.serialization.msgpack.MsgPack#decodeFromByteArray(/Users/kris/IdeaProjects/esensar/kotlinx-serialization-msgpack/serialization-msgpack/src/commonMain/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/MsgPack.kt:50)
    at eth.krisbitney.polywrap.msgpack#msgPackDecode(/Users/kris/IdeaProjects/krisbitney/polywrap-kt/src/commonMain/kotlin/eth.krisbitney.polywrap/msgpack/serialization.kt:66)
    at eth.krisbitney.polywrap.uriResolvers.extendable.UriResolverWrapper.$tryResolveUriWithImplementationCOROUTINE$129.invokeSuspend#internal(/Users/kris/IdeaProjects/krisbitney/polywrap-kt/src/commonMain/kotlin/eth.krisbitney.polywrap/uriResolvers/extendable/UriResolverWrapper.kt:87)

Expected behavior I expected the map to serialize using the dynamic serializer

krisbitney commented 1 year ago

This is actually resolved by using msgPackEncode(MapSerializer(String.Serializer, MsgPackDynamicSerializer), env)