How can enum be used with std.json.JSONValue in D? The implementing code does not have access to the module types and to! cannot be used, that's the reason for the CommonType!(OriginalType!()) call.
import std.json;
import std.stdio;
import std.traits;
enum Kind : string
{
dog = "Dog",
cat = "Cat",
pony = "Pony"
};
unittest
{
writeln("TEST: std.json.JSONValue for enum");
Kind animal = Kind.dog;
Kind[] pets = [Kind.cat, Kind.dog];
static if (is(typeof(animal) == enum))
{
writeln("enum");
}
//JSONValue a = JSONValue(animal); // <-- Assertion failed: (0), function unqualify, file mtype.c, line 2022.
JSONValue a = JSONValue(cast(CommonType!(OriginalType!(typeof(animal))))animal); // <-- this is OK
static if (is(typeof(pets) == enum))
{
writeln("array of enum");
}
//JSONValue p = JSONValue(pets); // <-- Assertion failed: (0), function unqualify, file mtype.c, line 2022.
//JSONValue p = JSONValue(???);
}