Serializer.registerSerializer

Registers a serializer for the given type.

The given callback will be called when a value of the given type is about to be serialized. This method can be used as an alternative to register. This method can also be used as an alternative to Serializable.toData.

This is method should also be used to perform custom serialization of third party types or when otherwise chaining an already existing type is not desired.

Parameters

dg void delegate

the callback that will be called when value of the given type is about to be serialized

Examples

class Base {}
class Foo : Base {}

auto archive = new XmlArchive!();
auto serializer = new Serializer(archive);

auto dg = (Base value, Serializer serializer, Data key) {
    // perform serialization
};

Serializer.registerSerializer!(Foo)(dg);

See Also

register registerDeserializer Serializable.toData

Meta