Add JsonEncoder and JsonDecoder implmentations to their Bson counterparts #1253
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Kotlinx requires the encoder to implement
JsonEncoder
andJsonDecoder
in order to encode genericJsonElement
types.The lack of this support for this came up many times when using KBson and KMongo previously and I'm hoping we can quickly mitigate this now that MongoDB has official support.
I've added each implementation to support most types on decoding and determine the best possible type on encoding to insert. It is somewhat assumed that if someone is encoding a
JsonElement
, then they will probably be decoding one as well and, therefore, type information is primarily for storage optimization.Unfortunately, Kotlinx writes all numbers as 64 bit integers first and never attempts to check for 32 bits or allow overriding the
JsonElementSerializer
behavior; this means that all integers will probably be written asint64
. Regardless, this should be a valuable add.