yshrsmz
05/07/2019, 9:04 AM@Serializable
data class UserProfile(val id:String)
fun test() {
val jsonElement = Json.nonstrict.toJson<UserProfile?>(NullableSerializer(UserProfile.serializer()), null)
println("jsonElement: $jsonElement")
}
Above code throws following error in kotlin 1.3.31 x serialization 1.1.0.
Caused by: kotlinx.serialization.SerializationException: No tag in stack for requested element
at kotlinx.serialization.TaggedEncoder.popTag(Tagged.kt:160)
at kotlinx.serialization.TaggedEncoder.encodeNull(Tagged.kt:92)
at kotlinx.serialization.internal.NullableSerializer.serialize(NullableSerializer.kt:39)
at kotlinx.serialization.json.internal.AbstractJsonTreeOutput.encodeSerializableValue(TreeJsonOutput.kt:174)
at kotlinx.serialization.CoreKt.encode(Core.kt:73)
at kotlinx.serialization.json.internal.TreeJsonOutputKt.writeJson(TreeJsonOutput.kt:29)
at kotlinx.serialization.json.Json.toJson(Json.kt:129)
has anyone experienced this issue?yshrsmz
05/07/2019, 9:50 AMenum class CollaboratorAffiliation {
OUTSIDE, DIRECT, ALL
}
fun test() {
val el = Json.nonstrict.toJson(EnumSerializer(CollaboratorAffiliation::class), CollaboratorAffiliation.ALL)
println("el: $el")
}
toJson with EnumSerializer also throws similar exception
Caused by: kotlinx.serialization.SerializationException: No tag in stack for requested element
at kotlinx.serialization.TaggedEncoder.popTag(Tagged.kt:160)
at kotlinx.serialization.TaggedEncoder.encodeEnum(Tagged.kt:108)
at kotlinx.serialization.internal.CommonEnumSerializer.serialize(Enums.kt:60)
at kotlinx.serialization.json.internal.AbstractJsonTreeOutput.encodeSerializableValue(TreeJsonOutput.kt:174)
at kotlinx.serialization.CoreKt.encode(Core.kt:73)
at kotlinx.serialization.json.internal.TreeJsonOutputKt.writeJson(TreeJsonOutput.kt:29)
at kotlinx.serialization.json.Json.toJson(Json.kt:129)
sandwwraith
05/14/2019, 8:20 PMtoJson
function: it expects an object, so serializing null
is impossible for nowyshrsmz
05/15/2019, 8:49 AM