This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Polymorphic deserialization with System.Text.Json
requires discriminator property to have the shortest JSON object key length
#2586
Labels
The following sample only works due to overriding the default discriminator property named
$type
(key length = 5) to$t
(key length = 2). Otherwise, the deserialization throws an exception.The System.Text.Json (STJ) docs state:
It's a pretty annoying .NET runtime issue that has been raised upstream. Not sure why STJ is opinionated about that, maybe for backwards compatibility with legacy systems? 🤔
This conflicts with
jsonb
columns (re-)ordering JSON object keys by length:Should we mention this quirk in the docs under Serialization with System.Text.Json?
Another idea is to let Marten align STJ and
jsonb
by configuring the STJ serializer via contract model.Similar to the
JsonNetContractResolver
via Json.NET serializer options, we could add the STJ analog that does something like this:The text was updated successfully, but these errors were encountered: