[JAVA-2769] Ignore idProperty for embedded classes Created: 02/Feb/18  Updated: 20/Mar/18  Resolved: 06/Feb/18

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

Type: Improvement Priority: Major - P3
Reporter: Ross Lawley Assignee: Ross Lawley
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to JAVA-2750 Pojo codec conversion missing id field Closed

 Description   

class Node {
  id: long
  left: Node
  right: Node
}

The id field will be converted to _id by annotations.
Consider ignoring the idProperty when encoding/decoding the embedded Nodes.

Relies on the context of the encoding / decoding to be known and handled by the PojoCodec.
It requires, some mechanisim to opt-into, so to prevent it being a breaking change.



 Comments   
Comment by Ross Lawley [ 06/Feb/18 ]

There are two issues preventing this being handled by a single class. Currently, no context about how a PojoCodec is used is passed around by Codecs. Secondly, the conventions applied by annotations overwrite the meta data about the property read and write name, so once the property name is changed - it is effectively lost.

However, storing data like so:

{ _id: 1,
  left: {id: 2},
  right: {id: 3}
}

Is possible but would require either: multiple classes and / or the use of an interface and discriminators.

As there are work arounds, I'm marking this as won't fix.

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