isPolicySerializable

Checks if a given policy supports custom serialization for a given type.

A class or struct type is custom serializable according to a policy if the policy defines a pair of toRepresentation/fromRepresentation functions. Any class or struct type that has this trait for the policy supplied to $D(serializeWithPolicy) will be serialized by using the return value of the policy toRepresentation function instead of the original value.

This trait has precedence over isCustomSerializable, isISOExtStringSerializable and isStringSerializable.

template isPolicySerializable (
alias Policy
T
) {}

Members

Variables

isPolicySerializable
enum bool isPolicySerializable;
Undocumented in source.

Examples

import std.conv;

// represented as a string when serialized
static struct S {
	int value;

	// dummy example implementations
	string toString() const { return value.to!string(); }
	static S fromString(string s) { return S(s.to!int()); }
}

static assert(isStringSerializable!S);

See Also

vson.serialization.serializeWithPolicy

Meta