Skip to content

.NET 7 polymorphic serialization support via System.Text.Json #77044

Closed Answered by eiriktsarpalis
shoaibshakeel381 asked this question in Q&A
Discussion options

You must be logged in to vote

So my question is why was current approach selected when it is still so limited.

See a similar question and the response here. TL;DR there's a few reasons:

  1. There would be ambiguity about what the polymorphic base type should be.
  2. It would be challenging to traverse the entire cross-assembly open hierarchy at runtime to detect all derived types decorated with the attribute. This is particularly true for the case of the source generator, for which derived types might not even be visible at compile time.
  3. This pattern was chosen intentionally to encourage users to model their DTO hierarchies in a single location.

For users that do require cross-assembly type hierarchies, it should still be…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@shoaibshakeel381
Comment options

Comment options

You must be logged in to vote
1 reply
@shoaibshakeel381
Comment options

Answer selected by shoaibshakeel381
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants