Interface IJsonSerializationCallbacks
- Namespace
- Nerdbank.Json
- Assembly
- Nerdbank.Json.dll
Receives notifications around the serialization and deserialization of a reference type.
public interface IJsonSerializationCallbacks
Remarks
This interface is supported only on reference types. Calling the methods on a struct boxes a copy, and mutations made by the callback are lost.
These callbacks are invoked by shape-generated object converters. A custom converter controls its own representation and is responsible for invoking callbacks when that is appropriate.
Callback exceptions are propagated to the serializer caller. Implementations should avoid initiating another top-level serialization operation for the same object.
On modern .NET, each method has an empty default implementation so an existing implementer keeps compiling
when it only supplies the callbacks it needs. On .NET Framework and .NET Standard 2.0 the methods are abstract,
matching Nerdbank.MessagePack.IMessagePackSerializationCallbacks.
Methods
OnAfterDeserialize()
Restores invariants or computed state after the object's constructor, properties, and extension data have been applied.
void OnAfterDeserialize()
OnAfterSerialize()
Performs any additional operations on an object after its properties and extension data have been written.
void OnAfterSerialize()
Remarks
Changes made by this callback are not written. It is not called when serialization of the object fails.
OnBeforeDeserialize()
Performs any additional operations on an object before any properties are set.
void OnBeforeDeserialize()
Remarks
A converter may not call this method if it is not supported. In particular, types with required or init properties or a deserializing constructor should expect this method to not be called if the default converter is used.
OnBeforeSerialize()
Performs any final validation or state preparation before the object's properties are read for serialization.
void OnBeforeSerialize()