-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Shouldn't a JsonIgnore property be included in JsonExtensionData property during deserialzation? #81521
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsAccording to the definition of JsonExtensionData:
When deserializing a property with JsonIgnore attribute, shouldn't it be a mismatching member because we ignore the property? Currently, System.Text.Json doesn't fill the JsonExtensionData property with a JsonIngore property: public class ClassWithIgnoredData
{
[JsonExtensionData]
public Dictionary<string, object> MyOverflow { get; set; }
[JsonIgnore]
public int MyInt { get; set; }
}
[Fact]
public async Task IgnoredDataShouldNotBeExtensionData()
{
ClassWithIgnoredData obj = await Serializer.DeserializeWrapper<ClassWithIgnoredData>(@"{""MyInt"":1}");
Assert.Equal(0, obj.MyInt);
Assert.Null(obj.MyOverflow);
}
|
I agree this seems counter intuitive (at least to me). I'd expect whatever is not being used to go to extension data but at the same time:
|
To voice a contrary opinion, I would expect The reasoning for this is that we've indicated in the model that we know the property should be in the data and that it should be ignored if it is. |
Closing as duplicate of #68895 @gregsdennis fair but currently contract model doesn't expose IsIgnored and IsIgnored was supposed to mean the same as not present in the model. I can see translating ignored as properties without getter or setter which would be equivalent to current behavior. The problem starts appearing when we have properties with same name on the derived class but not ignoring the property. Let's continue discussion in the other issue if needed |
According to the definition of JsonExtensionData:
When deserializing a property with JsonIgnore attribute, shouldn't it be a mismatching member because we ignore the property?
Currently, System.Text.Json doesn't fill the JsonExtensionData property with a JsonIngore property:
This is the unit test function in ExtensionDataTest
The text was updated successfully, but these errors were encountered: