You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importcom.github.jershell.kbson.KBsonimportkotlinx.serialization.Serializableimportorg.bson.BsonArrayimportorg.bson.BsonDocumentimportorg.bson.BsonElementimportorg.bson.BsonString
@Serializable
data classContainer(
valusers:MutableCollection<User>
)
@Serializable
data classUser(valname:String)
funmain() {
val bsonDocument =BsonDocument(
mutableListOf(
BsonElement("users", BsonArray(mutableListOf(BsonDocument("name", BsonString("a"))))),
)
)
println(KBson.default.parse(Container.serializer(), bsonDocument))
}
exception
Exception in thread "main" org.bson.BsonInvalidOperationException: readStartDocument can only be called when CurrentBSONType is DOCUMENT, not when CurrentBSONType is ARRAY.
at org.bson.AbstractBsonReader.verifyBSONType(AbstractBsonReader.java:689)
at org.bson.AbstractBsonReader.checkPreconditions(AbstractBsonReader.java:721)
at org.bson.AbstractBsonReader.readStartDocument(AbstractBsonReader.java:449)
at com.github.jershell.kbson.FlexibleDecoder.beginStructure(BsonFlexibleDecoder.kt:51)
at kotlinx.serialization.internal.AbstractPolymorphicSerializer.deserialize(AbstractPolymorphicSerializer.kt:121)
at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:257)
at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:16)
at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70)
at Container$$serializer.deserialize(a.kt:8)
at Container$$serializer.deserialize(a.kt:8)
at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:257)
at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:16)
at com.github.jershell.kbson.KBson.parse(KBson.kt:22)
at AKt.main(a.kt:22)
at AKt.main(a.kt)
if use List<User>, no exception
@Serializable
data classContainer(
valusers:List<User>
)
@Serializable
data classUser(valname:String)
funmain() {
val bsonDocument =BsonDocument(
mutableListOf(
BsonElement("users", BsonArray(mutableListOf(BsonDocument("name", BsonString("a"))))),
)
)
println(KBson.default.parse(Container.serializer(), bsonDocument))
}
The text was updated successfully, but these errors were encountered:
4o4E
changed the title
org.bson.BsonInvalidOperationException: readStartDocument can only be called when CurrentBSONType is DOCUMENT, not when CurrentBSONType is ARRAY.
exception when use MutableCollection
Dec 8, 2023
use
MutableCollection<User>
exception
if use
List<User>
, no exceptionThe text was updated successfully, but these errors were encountered: