Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BsonFlexibleDecoder ends SerialKind.Object but does not start #26

Open
markvogelnomad opened this issue May 19, 2023 · 3 comments
Open

Comments

@markvogelnomad
Copy link

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)
        ...
@ninja-
Copy link

ninja- commented May 20, 2023

👀

@ninja-
Copy link

ninja- commented May 20, 2023

I am curious what's the reproducer from DTO point of view? or does it only affect custom serializers?

@markvogelnomad
Copy link
Author

I mean it seems pretty obvious that the beginStructure does not account for SerialKind.OBJECT, but the endStructure does.
@ninja- Is this accounted for somewhere else that I missed?

NOTE: This may be a moot point as MongoDB has official drivers now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants