kevin-montrose / Jil

Fast .NET JSON (De)Serializer, Built On Sigil
MIT License
2.15k stars 253 forks source link

Deserialize crashes under .Net 5 #345

Closed IamIC closed 4 years ago

IamIC commented 4 years ago

The following illustrates a crash under .Net 5 / C# 9:

        class Person
        {
            public Person(int age, string name, Person[] data)
            {
                Age = age;
                Name = name;
                Data = data;
            }

            public int Age { get; set; }
            public string Name { get; set; }
            public Person[] Data { get; set; }
        }

        private void Test()
        {
            var p = new Person(99, "acrobat", new Person[]
                {
                    new Person(1, "abc", null),
                    new Person(2, "xyz", null)
                });

            var result = JSON.Serialize(p);

            // throws exception
            var p2 = JSON.Deserialize<Person>(result);
        }
NickCraver commented 4 years ago

The problem on this one isn't .NET 5, it's the lack of a parameterless constructor on Person. If you add one, it should work correctly (verified locally):

public Person() {}
IamIC commented 4 years ago

Thank you, that resolved it.