LitJSON/litjson

JsonMapper.ToJson throw InvalidCastException when enum is typeof uint

xiaobudie opened this issue · 0 comments

Enum like this:

enum ETest : uint
{
    A,
    B
}

JsonMapper.cs , line 807:

// Last option, let's see if it's an enum
if (obj is Enum) {
    Type e_type = Enum.GetUnderlyingType (obj_type);

    if (e_type == typeof (long)
        || e_type == typeof (uint)
        || e_type == typeof (ulong))
        writer.Write ((ulong) obj);
    else
        writer.Write ((int) obj);

    return;
}

Maybe, the cast first needs to go to uint from enum, and then to ulong. Same as long.

writer.Write ((ulong)(long) obj);
writer.Write ((ulong)(uint) obj);