JSONException if the input text does not represent an enum member.
ditto
import text.json.Decode : decodeJson; enum Enum { testValue, isHttp, } alias decode = decodeEnum!Enum; decodeJson!(Enum, decode)(JSONValue("TEST_VALUE")).should.be(Enum.testValue); decodeJson!(Enum, decode)(JSONValue("IS_HTTP")).should.be(Enum.isHttp); decodeJson!(Enum, decode)(JSONValue("")).should.throwA!JSONException; decodeJson!(Enum, decode)(JSONValue("ISNT_HTTP")).should.throwA!JSONException( "expected member of Enum, not ISNT_HTTP (or in D, 'isntHttp')");
Helper to decode a JSON style enum string (ENTRY_NAME) as a DStyle enum (entryName).
Use like so: alias decode = decodeEnum!EnumType; when forming your encode overload.