[JAVA-3545] Support sealed trait ADT in macro Created: 28/Sep/18 Updated: 30/Mar/22 |
|
| Status: | Backlog |
| Project: | Java Driver |
| Component/s: | Scala |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Andreas Vilinski | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 4 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
This definition works with mongodb case class macros:
But to serialize it with other serializers (avro4s) it should be like this instead - a trait:
But this code isn't supported if we use mongodb macros, failing with compile time error "No constructor unsupported class type". From my understanding the macro at this point already found subclasses and needs a constructor, which trait doesn't have. Don't know why the constructor is needed here, because the main class will be never instantiated. We have a pretty painful workaround to use them both - extending both class and trait:
A TreeLike codec provider is still needed to lookup the Tree codec in the registry. And it makes still less work compared to implementing all the codecs manually, which we already did earlier. Would be much better if macro would support traits as well. Is it possible? |
| Comments |
| Comment by Ross Lawley [ 28/Sep/18 ] |
|
Hi vilinski, Thanks for the ticket, I will investigate the feasibility when looking at the next release of the driver. Ross |