You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a type is virtual, the possibility exists that you might need to serialize a piece of information to identify which concrete class to use. Derived or implementing classes may have the same set of properties but signify different things as in a discriminated union, so an additional property should probably be synthesized to identify the correct concrete type.
A "$type"-style property is dangerous and not very pretty. With JSON.NET I usually have a JsonConverter that looks like this (very old implementation):
It adds the property "type": "1" for ConcreteType1 and "type": "2" for ConcreteType2. Names are usually more interesting and enum-like. This way known (and vetted!) concrete implementations will roundtrip correctly in an object graph.
I wonder if something similar would make sense for Gu.Xml, maybe even built in?
The text was updated successfully, but these errors were encountered:
If a type is virtual, the possibility exists that you might need to serialize a piece of information to identify which concrete class to use. Derived or implementing classes may have the same set of properties but signify different things as in a discriminated union, so an additional property should probably be synthesized to identify the correct concrete type.
A
"$type"
-style property is dangerous and not very pretty. With JSON.NET I usually have a JsonConverter that looks like this (very old implementation):It adds the property
"type": "1"
forConcreteType1
and"type": "2"
forConcreteType2
. Names are usually more interesting and enum-like. This way known (and vetted!) concrete implementations will roundtrip correctly in an object graph.I wonder if something similar would make sense for Gu.Xml, maybe even built in?
The text was updated successfully, but these errors were encountered: