[JAVA-4622] Support existing pojo annotations for encoding/decoding Java records Created: 18/May/22  Updated: 28/Oct/23  Resolved: 01/Jun/22

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

Type: Improvement Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
Related
related to JAVA-3567 Support Java record types Closed
Backwards Compatibility: Fully Compatible
Documentation Changes: Needed

 Description   

With our support for encoding/decoding Java records introduced in the 4.6.0 release, the driver introduced new annotations in the org.bson.codecs.record.annotations package (in the bson-record-codec module). The three annotations, BsonId, BsonRepresentation, and BsonProperty, mirror the already-existing ones that we have for POJOs in org.bson.codecs.pojo.annotations package (in the bson module). There are two problems with these annotations:

  1. mongodb-driver-core takes an implementation rather than an api dependency on bson-record-codec. This means that applications that depend on core (usually via driver-sync) won't be able to reference these annotations unless they take an explicit dependency on bson-record-codec
  2. The existing annotations can accidentally be applied even to records, but the driver ignores them. This will be really confusing to application authors.

We need to make a decision here. The two obvious choices are:

  1. Continue down the path of separate annotations for records and POJOs. For this route, we should
    1. Change the dependency to api so that applications will automatically have access to the annotations without explicitly adding a dependency on {
      Unknown macro: {bson-record-codec}

      }

    2. Report runtime errors if RecordCodec detects any of the pojo annotations 
  2. Support the pojo annotations in our record encoder/decoder. For this path, we should additionally deprecate the new annotations and stop documenting them.


 Comments   
Comment by Githook User [ 01/Jun/22 ]

Author:

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

Message: Support the existing pojo annotations on records (#944)

  • Look for the pojo annotations on the declared fields of the record.
  • Check for unsupported pojo annotations and throw CodecConfigurationException if found
  • Deprecate the record-specific annotations introduced in the 4.6 release

JAVA-4622
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/a2e3bebb6f66c29b39958f5a8b3baa71d188db40

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