Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4622

Support existing pojo annotations for encoding/decoding Java records

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.7.0
    • Affects Version/s: None
    • Component/s: BSON, POJO
    • Labels:
      None
    • Fully Compatible
    • Needed

      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.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: