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
{{ message }}
Repository navigation
Attribute foo used in [JsonPolymorphic(TypeDiscriminatorPropertyName = "foo")] does not get deserialized #79933
This came up recently but I cannot find the issue. We had a similar problem. The fact it has a setter implies you can change the underlying type by changing the value, which wouldn't make sense. We were using the property for introspection without a type-check and originally resolved it by putting JsonIgnore on the property (to prevent double serialization) and turned it into an abstract, get-only auto-property that returned the expected value by type, which is a variation on what was recommended by dotnet folks.
We ended up just dropping the property (which was entirely a convenience anyways) and just perform the type check ourself now.
yeah its not a super hard requirement for me to have this, either, but it just felt like a bug that it's always null. If that is indeed the desired behavior, it should at least be documented on JsonPolymorphic
Activity
pinkfloydx33 commentedon Dec 23, 2022
This came up recently but I cannot find the issue. We had a similar problem. The fact it has a setter implies you can change the underlying type by changing the value, which wouldn't make sense. We were using the property for introspection without a type-check and originally resolved it by putting JsonIgnore on the property (to prevent double serialization) and turned it into an abstract, get-only auto-property that returned the expected value by type, which is a variation on what was recommended by dotnet folks.
We ended up just dropping the property (which was entirely a convenience anyways) and just perform the type check ourself now.
sebader commentedon Dec 23, 2022
yeah its not a super hard requirement for me to have this, either, but it just felt like a bug that it's always null. If that is indeed the desired behavior, it should at least be documented on
JsonPolymorphiceiriktsarpalis commentedon Nov 22, 2023
This is by design, the type discriminator identifies types and so cannot be mapped to a run time property value.