[JAVA-2529] Make numeric codec implementations more lenient Created: 05/Jun/17  Updated: 29/Oct/23  Resolved: 04/Jul/17

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

Type: New Feature Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The numeric codec implementations are currently strict in that they will only decode the exact BSON type corresponding to the Java type of the codec. For instance, the LongCodec will decode BSON Int64 but fail for all other numeric BSON types. This was ok when the codecs were only used in the context of org.bson.Document because DocumentCodec selects the right codec based on the BSON type of the value.

In the context of POJO or case case codecs this become problematic. It's likely that users will define a POJO or class class with one numeric type but expect to decode multiple BSON numeric types with a single codec based on the field type. For instance, a POJO with a field of type long will need to decode a BSON Int32 value into that field, even though it will encode the value as an Int64 on the way out.



 Comments   
Comment by Githook User [ 04/Jul/17 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Made numeric codec implementations more lenient

JAVA-2529
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/c55a3a4c84117be3819524f0cec4148c6876686d

Comment by Ross Lawley [ 06/Jun/17 ]

PR: https://github.com/rozza/mongo-java-driver/pull/202

rstam I'd be grateful if you could also review this!

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