Closed jozkee closed 3 years ago
Changed to plural via email:
namespace System.Text.Json.Serialization
{
public partial class ReferenceHandler
{
// Existing:
// public static ReferenceHandler Preserve { get; }
public static ReferenceHandler IgnoreCycles { get; }
}
}
Background and Motivation
Even though we have covered the blocking issue of not being able to (de)serialize reference loops (https://github.com/dotnet/runtime/issues/30820, https://github.com/dotnet/runtime/issues/29900) by adding
ReferenceHandler.Preserve
to S.T.Json, there is many asks for adding an option equivalent to Json.NET'sReferenceLoopHandling.Ignore
.Motivations for doing this are:
ReferenceHandler.Preserve
may be too cumbersome and increases payload size.ReferenceHandler.Preserve
creates JSON incomprehensible by serializers other than S.T.Json and Json.NET.Proposed API
Usage Examples
Alternative Designs
This new API is being added to
ReferenceHandler
class since this can be considered as an alternative to deal with references that is more isolated to the circularity problem during serialization.Comparison with Newtonsoft.Json
Comparison with existing ReferenceHandler.Preserve setting in S.T.Json
Risks
One downside is that users are uanble to implement their own
ReferenceHandler
and cannot make their own "Ignore Cycle" handler. The discrimination between preserve and ignore would occur with an internal flag.Concerns of adding this feature (users must be aware of these problems when opting-in for it):