Uses Base64 representation for ubyte[] instead of to!string
Deserializes and returns a serialized value.
Deserializes and returns a serialized value, interpreting values according to Policy when possible.
Attribute for overriding the field name during (de-)serialization.
Serializes a value with the given serializer.
Serializes a value with the given serializer, representing values according to Policy when possible.
Attribute for representing a struct/class as an array instead of an object.
Attribute for forcing serialization of enum fields by name instead of by value.
Makes this nullable as if it is not a nullable to the serializer. Ignores the field completely when it is null.
Attribute for marking non-serialized fields.
Attribute marking a field as optional during deserialization.
User defined attribute (not intended for direct use)
User defined attribute (not intended for direct use)
Chains serialization policy.
Default policy (performs no customization).
Checks if a given type has a custom serialization representation.
Checks if a given type has an ISO extended string serialization representation.
Checks if a given policy supports custom serialization for a given type.
Checks if a given type has a string serialization representation.
The following rules are applied in order when serializing or deserializing a certain type:
Note that no aliasing detection is performed, so that pointers, class references and arrays referencing the same memory will be serialized as multiple copies. When in turn deserializing the data, they will also end up as separate copies in memory.
By default, the field name of the serialized D type (for struct and class aggregates) is represented as-is in the serialized result. To circumvent name clashes with D's keywords, a single trailing underscore of any field name is stipped, so that a field name of version_ results in just "version" as the serialized value. Names can also be freely customized using the @name annotation.
Associative array keys are always represented using their direct string representation.
Serializers are implemented in terms of a struct with template methods that get called by the serialization framework:
struct ExampleSerializer { enum isSupportedValueType(T) = is(T == string) || is(T == typeof(null)); // serialization auto getSerializedResult(); void beginWriteDocument(TypeTraits)(); void endWriteDocument(TypeTraits)(); void beginWriteDictionary(TypeTraits)(size_t length); [OR] void beginWriteDictionary(TypeTraits)(); void endWriteDictionary(TypeTraits)(); void beginWriteDictionaryEntry(ElementTypeTraits)(string name); void endWriteDictionaryEntry(ElementTypeTraits)(string name); void beginWriteArray(TypeTraits)(size_t length); void endWriteArray(TypeTraits)(); void beginWriteArrayEntry(ElementTypeTraits)(size_t index); void endWriteArrayEntry(ElementTypeTraits)(size_t index); void writeValue(TypeTraits, T)(T value); // deserialization void readDictionary(TypeTraits)(scope void delegate(string) entry_callback); void beginReadDictionaryEntry(ElementTypeTraits)(string); void endReadDictionaryEntry(ElementTypeTraits)(string); void readArray(TypeTraits)(scope void delegate(size_t) size_callback, scope void delegate() entry_callback); void beginReadArrayEntry(ElementTypeTraits)(size_t index); void endReadArrayEntry(ElementTypeTraits)(size_t index); T readValue(TypeTraits, T)(); bool tryReadNull(TypeTraits)(); // skipValue() is optional. It will be called by the entry_callback in readDictionary // whenever the key passed to the entry_callback cannot be found. void skipValue(); }
The TypeTraits type passed to the individual methods has the following members:
ElementTypeTraits have the following additional members:
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
© 2013-2016 rejectedsoftware e.K.
Generic serialization framework.
This module provides general means for implementing (de-)serialization with a standardized behavior.