[JAVA-2013] Make Bson interface Serializable and Clonable Created: 12/Oct/15 Updated: 13/Oct/15 Resolved: 13/Oct/15 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | 3.0.4, 3.1.0 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Kamesh | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Major Change |
| Description |
|
Currently all the classes which implements org.bson.conversions.Bson interface are Serializable and Cloneable. It would be good if Bson interface itself extends those interfaces. Also when we do programming against interface (Bson), this is necessary. |
| Comments |
| Comment by Jeffrey Yemin [ 13/Oct/15 ] |
|
Yes, you're right about BasicDBObject. It's Serializable and Cloneable by virtue of indirectly extending HashMap. Apologies for missing that earlier. As I said earlier, we can't make Bson extend Serializable without breaking binary compatibility for any existing classes that already implement Bson but are not Serializable. I think this was the right decision: notice, for example, that in the JDK interfaces like Map and Collection do not extend Serializable (or Cloneable). Both these interfaces place non-negligible requirements on implementing classes and are therefore too onerous for widely implemented interfaces like these. For these reasons, I'm closing this as Won't Fix. As a workaround, you can convert any Bson instance to a BsonDocument via the org.bson.conversions.Bson#toBsonDocument method. BsonDocument, unlike Bson, is both Cloneable and Serializable. |
| Comment by Kamesh [ 13/Oct/15 ] |
|
I am referring java doc and there it mentioned that BasicDBObject is both Serializable and Cloneable. Yes, Document is not Cloneable, however, it is Serializable. I feel it would be good to have Bson as at least Serializable. Otherwise, an application requiring a serialized object may not use Bson, rather have to use one of the implementation classes. Is there any reason behind not making Bson as Serializable. If you think, it is not a valid ask, please feel free to close this as invalid. |
| Comment by Jeffrey Yemin [ 12/Oct/15 ] |
|
It's not the case that all classes which implement Bson are Serializable and Cloneable.
Furthermore, making Bson extends Serializable and Cloneable would break binary compatibility for any third parties that are already implementing Bson. For that reason alone, we can't make this change. |