-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type discriminator is lost when serializing a Result<T> using [TranslateResultToActionResult] #204
Comments
Is this causing a real world problem? Your controllers should typically never return just an object and not an ActionRest, in order to support NotFound, etc. |
Our controllers aren't returning just an object, they are returning a Result. But since the type discriminator for T is lost (unlike if I returned T directly), I cannot have polymorphic endpoints returning Result |
Right but based on what you're writing above, if they returned |
|
I had a small look into it, the problem seems to be that in the ObjectResult the DeclaredType is null. So when I add the DeclaredType to the ObjectResult I get the discriminator.
|
When serializing a derived type as its base type, System.Text.Json will use an extra type discriminator field to communicate the actual type of the serialized data. Given a base class
Base
and a derived typeDerived
, I have observed the following behavior:Base
will correctly include the type discriminator.ActionResult<Base>
will include the type discriminator.Result<Base>
will include the properties of the derived type but it will NOT include the type discriminator.Minimal reproducible example: https://github.com/uflowie/ResultLostTypeDiscriminator
The text was updated successfully, but these errors were encountered: