runtime
runtime copied to clipboard
System.Text.Json.JsonSerializer can not handle recursion, even when there is none
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);
Fixed in Preview 9 - thanks :-)
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!