[JAVA-372] BSON.encode/decode should support primitive wrapper types as well Created: 08/Jun/11  Updated: 19/Oct/16  Resolved: 19/Oct/16

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

Type: Improvement Priority: Minor - P4
Reporter: Thilo Planz Assignee: Antoine Girbal
Resolution: Done Votes: 0
Labels: bson
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

Whereas JSON.parse can parse the "scalar" types as well, and as such can return not just BSONObject, but also String or Long, BSON.encode/decode only work with BSONObject.

https://jira.mongodb.org/browse/JAVA-298

I'd like to be able to also do for example

byte[] aLong = BSON.encode(1l);
byte[] aString = BSON.encode("string");

For encode, this could be added as a new overload, for decode it would need to change the return type (from BSONObject to Object), so for the sake of compatibility, one would need to add a new method name.



 Comments   
Comment by Thilo Planz [ 26/Sep/11 ]

After another close look at the BSON spec, at least the decode/parse part of this cannot be done in symmetry to the JSON code: Unlike the various typed elements (including embedded documents), a BSON "document" has no special type indicator. The binary data just consists of the length field, the content, and a trailing null.

So, you cannot call BSON.decode with binary data without already knowing that the data will be a document (and not anything else).

Retracting this feature request, feel free to close it.

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