runtime icon indicating copy to clipboard operation
runtime copied to clipboard

System.Text.Json.JsonSerializer can not handle recursion, even when there is none

Open tabinnorway opened this issue 7 years ago • 2 comments

The following will crash, rendering .net core useless for most real world applications. Tested with Preview 8. Newtonsoft handles it with no issues. There are huge amounts of situations where an object can contain "child" objects of its own class. Not just folders.

   public class AUser
    {
        public string Fullname { get; set; }
        public AFolder Folder { get; set; }
    }

    public class AFolder
    {
        public string Name { get; set; }
        public IList<AFolder> SubFolders { get; set; }
    }

...
var us = new AUser {
   Folder = new AFolder {
      SubFolders = null // For good measure
   }
};

var t = System.Text.Json.JsonSerializer.Serialize(us);

tabinnorway avatar Sep 05 '19 08:09 tabinnorway

Fixed in Preview 9 - thanks :-)

tabinnorway avatar Sep 05 '19 09:09 tabinnorway

This doesn't repro in Preview 9 builds.

This is the output:

{"Fullname":null,"Folder":{"Name":null,"SubFolders":null}}

Try upgrading to the latest SDK/package.

This is a duplicate of https://github.com/dotnet/corefx/issues/40608, https://github.com/dotnet/corefx/issues/40050, and https://github.com/dotnet/corefx/issues/39769 /cc @steveharter

Thanks for the report!

ahsonkhan avatar Sep 05 '19 09:09 ahsonkhan