<PackageReference Include="System.Text.Json" Version="8.0.0-preview.3.23174.8" />

ReferenceResolver

public abstract class ReferenceResolver
Defines how the JsonSerializer deals with references on serialization and deserialization. Defines the core behavior of preserving references on serialization and deserialization.
protected ReferenceResolver()

Initializes a new instance of the ReferenceResolver class.

public abstract void AddReference(string referenceId, object value)

Adds an entry to the bag of references using the specified id and value. This method gets called when an $id metadata property from a JSON object is read.

public abstract string GetReference(object value, out bool alreadyExists)

Gets the reference identifier of the specified value if exists; otherwise a new id is assigned. This method gets called before a CLR object is written so we can decide whether to write $id and enumerate the rest of its properties or $ref and step into the next object.

public abstract object ResolveReference(string referenceId)

Returns the CLR reference type object related to the specified reference id. This method gets called when $ref metadata property is read.