A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/GreanTech/AtomEventStore/wiki/Writing-a-custom-XML-serializer below:

Writing a custom XML serializer · GreanTech/AtomEventStore Wiki · GitHub

AtomEventStore takes care of serializing and deserializing all well-known Atom XML types, but these are ultimately only envelopes. The actual content (the events) is supplied by the client, and being a general-purpose library, AtomEventStore has no knowledge of the custom event types being written and read.

AtomEventStore comes with a few built-in XML serializer implementations. These should be enough for most purposes, but you can also implement your own XML serializer if you have special needs.

In order to implement a custom XML serializer for AtomEventStore, you must implement the IContentSerializer interface, which only defines two methods:

public interface IContentSerializer
{
    void Serialize(XmlWriter xmlWriter, object value);

    XmlAtomContent Deserialize(XmlReader xmlReader);
}

As their names imply, these methods serialize and deserialze content.

Before AtomEventStore writes events to the underlying storage mechanism, it serializes the relevant Atom Feed page to XML. The content of each Atom Entry is serialized using IContentSerializer.Serialize.

In order to implement this method, you must write the value argument to the provided xmlWriter. The XML you write must be in a format that subsequently enables your implementation of IContentSerializer.Deserialize to interpret it and rehydrate the object with the correct values.

When AtomEventStore reads events from the underlying storage mechanism, it deserializes the Atom XML to objects. The content of each Atom Entry element is deserialized using IContentSerializer.Deserialize.

Your implementation must be able to correctly interpret the XML written by your implementation of IContentSerializer.Serialize.

The source code for AtomEventStore contains various implementations of IContentSerializer, including

These are fully functioning implementations, and not particularly complex, and since they are actual production code, they provide better examples than any toy example that could be provided here.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4