--- title: "Custom Element Serialization [Writable] (Advanced)" slug: "custom-element-serialization-writable-advanced" description: "Learn how to customize storage and storage-related events for Custom Element Serialization using interface code and implementation examples." updated: 2026-04-27T20:46:53Z published: 2026-04-28T14:13:01Z canonical: "documentation.decisions.com/custom-element-serialization-writable-advanced" --- > ## Documentation Index > Fetch the complete documentation index at: https://documentation.decisions.com/llms.txt > Use this file to discover all available pages before exploring further. # Custom Element Serialization [Writable] (Advanced) ## Overview In addition to marking up the object with attributes, there are a few interfaces that allow for customization of the storage and hooking events around the storage. ### Specifying Custom Serialization Using this interface, logic can be run on what to store, do conversions, and construction of unstable objects. ```shell public interface IWritable { void Read(ReadStream stream); void Save(WriteStream stream); } ``` ### Specifying Behavior Before Read Using this interface, the object can be aware of being read in and can behave differently. An example use case would be for not taking some action when being read (deserialized) but performing action after. ``` public interface IBeforeRead { void BeforeRead(); } ``` ### Specifying Behavior Before Write Using this interface, objects can be aware of being written. This is often used to rearrange data before the write happens. ``` public interface IBeforeWrite { void BeforeWrite(); } ``` ### Specifying Behavior After Reading If some action needs to take place after an object (full object graph) has been read, this interface allows this to be changed. ``` public interface IReadComplete { void ReadComplete(); } ``` ### Changing Fault Behavior If different behavior is desired when there is a problem, this interface allows adjustment. ``` public interface ISerializationFaultPolicyBehavior { SerializationFaultPolicy GetDeserializationFaultBehavior(); } public enum SerializationFaultPolicy { ThrowException, Tolerant } ``` #### Code Example: ``` public class Person : IWritable, IBeforeRead, IBeforeWrite, IReadComplete, ISerializationFaultPolicyBehavior { private string name; public void Read(ReadStream stream) { name = stream.GetValue("personname"); } public void Save(WriteStream stream) { stream.Add("personname", name); } public void BeforeRead() { } public void BeforeWrite() { if (name == null) name = "unknown"; } public void ReadComplete() { if (name.Contains(" ")) name = name.Replace(" ", ""); } public SerializationFaultPolicy GetDeserializationFaultBehavior() { return SerializationFaultPolicy.Tolerant; } } ```