[JAVA-2296] Parts of the legacy BSON API do not handle documents containing Decimal128 values Created: 03/Sep/16  Updated: 19/Oct/16  Resolved: 08/Sep/16

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Chunming Li (Inactive) Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: rc
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
related to JAVA-2298 Improve test coverage for legacy BSON... Closed

 Description   

This is using 3.4.0-SNAPSHOT as of today, when decoding a mgo encoded object with decimal128 values.

org.bson.BSONException: Unexpected BSON type: DECIMAL128
	at org.bson.BsonBinaryReader.doSkipValue(BsonBinaryReader.java:357) ~[mongo-java-driver-3.4.0-SNAPSHOT.jar:na]
	at org.bson.AbstractBsonReader.skipValue(AbstractBsonReader.java:492) ~[mongo-java-driver-3.4.0-SNAPSHOT.jar:na]
	at org.bson.LazyBSONObject.keySet(LazyBSONObject.java:151) ~[mongo-java-driver-3.4.0-SNAPSHOT.jar:na]
	at com.mongodb.LazyDBCallback.createObject(LazyDBCallback.java:41) ~[mongo-java-driver-3.4.0-SNAPSHOT.jar:na]
	at org.bson.LazyBSONCallback.gotBinary(LazyBSONCallback.java:41) ~[mongo-java-driver-3.4.0-SNAPSHOT.jar:na]
	at org.bson.LazyBSONDecoder.decode(LazyBSONDecoder.java:63) ~[mongo-java-driver-3.4.0-SNAPSHOT.jar:na]
	at com.mongodb.LazyDBDecoder.readObject(LazyDBDecoder.java:39) ~[mongo-java-driver-3.4.0-SNAPSHOT.jar:na]

On the encoding side, the following test case will complain about Can't serialize class org.bson.types.Decimal128.

        BSONObject obj = new BasicBSONObject();
        obj.put("i", Decimal128.parse("1"));
 
        OutputBuffer ob = new BasicOutputBuffer(); 
        DBEncoder encoder = DefaultDBEncoder.FACTORY.create();
        encoder.writeObject(ob, obj);



 Comments   
Comment by Githook User [ 08/Sep/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2296: Add a note about the breaking API change in BSONCallback to the upgrading section of the reference documentation
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/89d95150ee26a55fc318f78a8723d90d8044343f

Comment by Githook User [ 08/Sep/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2296: Support Decimal128 in com.mongodb.util.JSON
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/60887e412698915e1ac632c51e024f615b39d7ee

Comment by Githook User [ 08/Sep/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2296: Support Decimal128 for BasicBSONDecoder, BasicBSONDecoder, and BSONCallback

Note: this breaks binary compatibility for any implementors of BSONCallback
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/88bc69a6e9d99d0c17f7233ff2e55265605a608d

Comment by Jeffrey Yemin [ 06/Sep/16 ]

I've been exploring ways to add support for Decimal128 in the existing BSONDecoder implementations. Two possibilities:

  1. Break binary compatibility by adding a gotDecimal128 method to BSONCallback.
    • On the plus side, it forces upgraders who implement BSONCallback (which isn't all that common unless you write your own Decoder implementation) to deal with Decimal128. I also reviewed all the Java MongoDB ODMs that I know of (mongojack, jongo, morphia, spring-data-mongodb), which are the most likely candidates to implement BSONCallback, and none of them actually do.
    • On the minus side, it breaks binary compatibility in a way that could result in a runtime error regardless.
  2. Add a new interface, BSONDecimal128Callback, which a single gotDecimal128 method, and in the driver's BSONDecoder implementations do an instanceof check on BSONCallback for this new interface.
    • On the plus side, it preserves binary compatibility.
    • On the minus side, upgraders have to read the release notes to realize they have to take any action.
Comment by Chunming Li (Inactive) [ 06/Sep/16 ]

jeff.yemin Unfortunately we do use BasicDBDecoder in a few places. I'm not familiar enough with the 3.0+ driver. What are our alternatives here?

Comment by Githook User [ 06/Sep/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2296: Support Decimal128 in BasicBSONEncoder for the legacy API.

Note that Decimal128 is NOT supported by BasicBSONDecoder, as that would required the addition of a method to the public intervace BSONCallback.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/a6b073e766e0c57f5c4649df8090a8818cc77dcb

Comment by Jeffrey Yemin [ 06/Sep/16 ]

Hi chunming.li Do you also rely on DefaultDBDecoder to decode DBObject instances that may contain Decimal128 instances? If so, that's going to a problem: BSONCallback is a public API that was not designed for extensibility to new BSON types, so we can't add Decimal128 support there without breaking binary compatibility.

Comment by Jeffrey Yemin [ 06/Sep/16 ]

Still need to look at the encoding side

Comment by Githook User [ 06/Sep/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2296: Fix Codenarc warning
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/40785628a75e2f639a683559f9bb06a635128830

Comment by Githook User [ 06/Sep/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2296: Refactor and improve test coverage for Bson Reader and Writer implementations
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/34dd4f1cb4104922149d9d5ff4b06c63636a12aa

Comment by Githook User [ 06/Sep/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2296: Add case for Decimal128 to AbstractBsonWriter.pipe
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/bb600b461f724dec8ff6f85194ae8f5766d795d1

Comment by Githook User [ 06/Sep/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2296: Add case for Decimal128 to BsonBinaryReader#skipValue
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/ae720ef6cfed3c3d3b558ddba8fc54c0e59b41b4

Comment by Githook User [ 06/Sep/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2296: Add case for Decimal128 to JsonReader#skipValue
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/60bbe6425e03bcb8280d75f67ff1b047341619a1

Generated at Thu Feb 08 08:56:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.