Okay with the PR merged, this works for me now:
template P(T) if (is(T == enum)) {
static string toRepresentation(T v) { return v.to!string.toLower(); }
static T fromRepresentation(string str) { return str.toUpper().to!T; }
}
enum E {
RED,
GREEN
}
assert(serializeWithPolicy!(JsonSerializer, P)(E.RED) == Json("red"));
Using JsonStringSerializer
directly is a little ugly, as it expects an output range. I'll probably add a serializeToJsonWithPolicy
kind of function to mitigate that.