[CSHARP-4835] Support BsonKnownTypes attribute on interface types Created: 05/Nov/23 Updated: 14/Nov/23 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Henry Yu | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
`System.Text.Json` can support polymorphic JSON serialization/deserialization using an interface as base type. I think MongoDB should support `BsonKnownTypes` attribute on interface types as well. |
| Comments |
| Comment by Boris Dogadov [ 09/Nov/23 ] | ||||||||||||||||
|
Hi henry@schedgo.com , This is a good point. We will be investigating this use case further. Please follow this ticket for further updates. | ||||||||||||||||
| Comment by Henry Yu [ 09/Nov/23 ] | ||||||||||||||||
|
That does work! However, I would prefer a descriptive way of doing it since I build class libraries for downstream packages to consume. I would not want consumers to need to imperatively call some methods to register types that they do not own or put some startup code in a static constructor that could slow down startup of downstream executables. Henry{} | ||||||||||||||||
| Comment by Boris Dogadov [ 09/Nov/23 ] | ||||||||||||||||
|
For interfaces serialization, driver specifies the concrete type discriminator, which is used for deserializing as well.
Please let us know if this addresses your question, or is there any other scenario which is not supported by driver. | ||||||||||||||||
| Comment by PM Bot [ 05/Nov/23 ] | ||||||||||||||||
|
Hi henry@schedgo.com, thank you for reporting this issue! The team will look into it and get back to you soon. |