mongo-java-driver icon indicating copy to clipboard operation
mongo-java-driver copied to clipboard

Add JsonEncoder and JsonDecoder implmentations to their Bson counterparts

Open markvogelnomad opened this issue 2 years ago • 3 comments

Kotlinx requires the encoder to implement JsonEncoder and JsonDecoder in order to encode generic JsonElement 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 as int64. Regardless, this should be a valuable add.

markvogelnomad avatar Nov 07 '23 18:11 markvogelnomad

Hi @markvogelnomad, many thanks for the excellent PR!

I've added JAVA-5239 to track the feature request.

Cheers,

Ross

rozza avatar Nov 08 '23 16:11 rozza

Appreciate it!

I've pushed one more non-functional change to attempt to comply with the checks; I will leave it alone at this point to allow feedback or modification, if required.

markvogelnomad avatar Nov 08 '23 16:11 markvogelnomad

Hi @markvogelnomad thanks for the PR. We are backlogging this ticket for now, as we would like to dedicate a little more time reviewing this PR and ensuring we do our proper due diligence before merging. Please follow JAVA-5239 for updates.

tom-selander avatar Nov 20 '23 16:11 tom-selander

Closing in favour of #1459. I used this as the base and added you as a co-author in the commit. The core difference is feature detection is used to see if json support is available, rather than taking a hard dependency.

rozza avatar Jul 24 '24 15:07 rozza