[JAVA-2223] support interfaces for field types Created: 13/Jun/16  Updated: 03/Apr/17  Resolved: 03/Apr/17

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

Type: New Feature Priority: Major - P3
Reporter: Justin Lee Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: POJO

 Description   

If a field is declared to be a Foo where Foo is an interface, we need a mechanism to indicate the concrete class to instantiate when deserializing. For embedded entities we can rely on the discriminator value in the nested document. For the case where foo is a enum that implements Foo, we lack sufficient context to rehydrate those objects. Options:

  1. Require an annotation (or programmatic configuration) to define the concrete class. The container types (List/Map/Set) already use this to guess at the appropriate container type to create. We could expose this for use in the more general case
  2. We could serialize these cases as documents containing _t with the concrete type and the value. This would make queries slightly awkward outside of Java so that's slightly less attractive. It's more flexible at runtime though since we're not tying that interface implementation to just one type which kind of defeats the purpose of programming to interfaces.


 Comments   
Comment by Ross Lawley [ 03/Apr/17 ]

See JAVA-1812 for the commit containing the commit covering this ticket.

Comment by Ross Lawley [ 16/Mar/17 ]

Other than List/Map/Set I'm not sure what other specialisation we need. As long as you have a codec for the field's class then it will hydrate as required and cast to the interface type.

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