[JAVA-4476] Make Java client model classes implement Serializable interface Created: 05/Feb/22  Updated: 25/Aug/23  Resolved: 14/Feb/22

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

Type: New Feature Priority: Unknown
Reporter: Nir Tsruya Assignee: Jeffrey Yemin
Resolution: Declined Votes: 0
Labels: external-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

As a Java developer, I would like to make the Java client model classes implement the Serializable interface. 

Motivation

I am working on a mongodb connector for the [Apache Flink project|https://flink.apache.org/]

Internally, Flink is using java serialization to save the records it is working on in a state which in turn used to recover from failures etc, as well as for passing records between different tasks in the pipeline.
I have noticed the mongodb client model classes are not Serializable for instance, classes such as [WriteModel|https://github.com/mongodb/mongo-java-driver/blob/master/driver-core/src/main/com/mongodb/client/model/WriteModel.java] and its subclasses or the different Options like [ReplaceOptions|https://github.com/mongodb/mongo-java-driver/blob/master/driver-core/src/main/com/mongodb/client/model/ReplaceOptions.java

AC

  • Make the Java client model classes implement the Serializable interface. 


 Comments   
Comment by Jeffrey Yemin [ 14/Feb/22 ]

No problem. Please let us know what you decide to do, and if there's anything else you need from the driver to enable this integration.

Comment by Nir Tsruya [ 14/Feb/22 ]

Thank you for the investigation and quick response.

It makes sense

Comment by Jeffrey Yemin [ 07/Feb/22 ]

nirtsr@gmail.com. I see a number of problems with adding this to the driver:

  • Many of the fields are of type org.bson.conversions.Bson, which does not itself extend Serializable.
  • WriteModel is generic over T, and there is no requirement that T extends Serializable
  • We often add new fields to the options classes, which would make it difficult to provide guarantees that older versions of those classes could deserialize newer ones

I think any approach that is taken by Flink has to involve first converting all instances of org.bson.conversions.Bson and of T into a BsonDocument, which does extend Serializable. But do to that requires knowledge of which CodecRegistry is being using by the application, which WriteModel does not have in isolation (the driver relies on whatever CodecRegistry is configured in the MongoCollection to actually serialize write models).

Generated at Thu Feb 08 09:02:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.