Replies: 3 comments 8 replies
-
System.Text.Json by default work with the static type in signature (base type), not the dynamic type of the object (derived type) unless the static type is You need to enable Polymorphic serialization to get such dynamic behavior. The extra discriminator isn't required when deserialization is not used. |
Beta Was this translation helpful? Give feedback.
-
@huoyaoyuan, solved like a charm. But can't we just configure a simple boolean flag? Compare these codes:
with
The second code is not only more, but also not extensible. What if I want to distribute a library? What if a developer wants to create another type of |
Beta Was this translation helpful? Give feedback.
-
@huoyaoyuan, thank you so much for your help. This was one of the best help I ever received. Fast, correct, and informative. Wish you good luck. |
Beta Was this translation helpful? Give feedback.
-
I have a base class called
Filter
. Many derived classes inherit from it including:I have a general action that searches the entire code, finds
GetFilters
methods, calls them, combines the results into a list, and returns it:The point is that each
GetFilter
might return different types of filters. And when I see thefilters
before it returns to the client, I can see that each derived class has its own properties.For example the
RangeFilter
has theMin
andMax
property.Yet when I see the output JSON in the browser, I only see properties of the
Filter
class.How can I solve this?
Beta Was this translation helpful? Give feedback.
All reactions