Skip to content
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

When a polymorphic interface type used for an object, deserialization throwing NRE #29635

Closed
buyaa-n opened this issue May 23, 2019 · 2 comments · Fixed by dotnet/corefx#38061
Labels
area-System.Text.Json bug help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@buyaa-n
Copy link
Contributor

buyaa-n commented May 23, 2019

I am aware of ploymorphism not supported yet, but i think JsonException should be thrown instead of NRE

        public class MyClass
        {
            public string Value { get; set; }

            public IThing Thing { get; set; }
        }

        public interface IThing
        {
            int Number { get; set; }
        }

        public class MyThing : IThing
        {
            public int Number { get; set; }
        }

        [Fact]
        public void AssertDoesDeserialize()
        {
            const string json = @"{
""Value"": ""A value"",
""Thing"": {
""Number"": 123
}
}";
            Assert.Throws<JsonException>(() =>
            {
                JsonSerializer.Parse<List<MyClass>>(json);
            });
            /* this test works if not use any interface type, but i guess that is expected as polymorphism not supported yet
                        MyClass myClass = JsonSerializer.Parse<MyClass>(json);
                        Assert.NotNull(myClass);
                        Assert.Equal("A value", myClass.Value);
                        Assert.NotNull(myClass.Thing);
                        Assert.Equal(123, myClass.Thing.Number);
            */
        }
@ahsonkhan
Copy link
Contributor

This is one of the specific instances related to https://github.com/dotnet/corefx/issues/37545 and should be fixed. cc @steveharter

@MarcoRossignoli
Copy link
Member

Up for grab?I'm working also on other similar

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json bug help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants