Closed mikolaj-milewski closed 7 months ago
Deserialization of derived type works only when "$type" is first attribute in JSON object
Not a bug, and also an incorrect statement. Newtonsoft.Json also supports scenarios where the "$type"
metadata property is not the first property in a Json object.
However, since this pretty much requires the serializer to buffer data (up to the point where it comes across the "$type"
property), which is incurring both a perf and memory cost, this behavior needs to be explicitly enabled by setting JsonSerializerSettings.MetadataPropertyHandling
to MetadataPropertyHandling.ReadAhead
.
Thank you for an explanation!
Source/destination types
Source/destination JSON
Expected behavior
I'd like to get instance of
Derived
class.Actual behavior
I'm getting instance of
Base
class.Steps to reproduce