-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.Jsonjson-functionality-docMissing JSON specific functionality that needs documentingMissing JSON specific functionality that needs documenting
Milestone
Description
One of the key features of JSON.NET serialization was the ReferenceLoopHandling
which gives the ability to ignore the reference loops likes this :
public class Employee
{
public string Name { get; set; }
public Employee Manager { get; set; }
}
private static void Main()
{
var joe = new Employee { Name = "Joe - User" };
var mike = new Employee { Name = "Mike - Manager" };
joe.Manager = mike;
mike.Manager = mike;
var json = JsonConvert.SerializeObject(joe, new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
Console.WriteLine(json);
}
And it produces the appropriate result :
{
"Name": "Joe User",
"Manager": {
"Name": "Mike Manager"
}
}
However, I couldn't find such a feature in System.Text.JSON, And when I've tried to Serialize the same object with JsonSerializer :
private static void Main()
{
var joe = new Employee { Name = "Joe User" };
var mike = new Employee { Name = "Mike Manager" };
joe.Manager = mike;
mike.Manager = mike;
var json = JsonSerializer.ToString(joe, new JsonSerializerOptions
{
WriterOptions = new JsonWriterOptions
{
Indented = true,
}
});
Console.WriteLine(json);
}
I've got this exception :
System.InvalidOperationException: 'CurrentDepth (1000) is equal to or larger than the maximum allowed depth of 1000. Cannot write the next JSON object or array.'
So, Is this feature exist in System.Text.Json now that I couldn't find it?
And if not, Are there any plans to support this?
FIVIL, pinkfloydx33, xsoheilalizadeh, PejmanNik, 1saeedsalehi and 75 more
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.Jsonjson-functionality-docMissing JSON specific functionality that needs documentingMissing JSON specific functionality that needs documenting