Skip to content

BsonFlexibleDecoder ends SerialKind.Object but does not start #26

@markvogelnomad

Description

@markvogelnomad

When decoding a SerialKind.OBJECT the BsonFlexibleDecoder does not start the document read, but it does end it.

https://github.com/jershell/kbson/blob/master/src/main/kotlin/com/github/jershell/kbson/BsonFlexibleDecoder.kt#L61

This causes the following error when attempting to decode objects even if they are {} in the database:

org.bson.BsonInvalidOperationException: readEndDocument can only be called when ContextType is DOCUMENT or SCOPE_DOCUMENT, not when ContextType is TOP_LEVEL.
	at org.bson.AbstractBsonReader.throwInvalidContextType(AbstractBsonReader.java:654)
	at org.bson.AbstractBsonReader.readEndDocument(AbstractBsonReader.java:347)
	at com.github.jershell.kbson.FlexibleDecoder.endStructure(BsonFlexibleDecoder.kt:61)
	at kotlinx.serialization.internal.ObjectSerializer.deserialize(ObjectSerializer.kt:57)
	at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:257)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:16)
	at com.application.codec.CustomCodec.decode(CustomCodec.kt:71)
        ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions