rpgmaker / NetJSON

Faster than Any Binary? Benchmark: http://theburningmonk.com/2014/08/json-serializers-benchmarks-updated-2/
MIT License
231 stars 29 forks source link

Enum flags do not work #173

Closed physhi closed 7 years ago

physhi commented 7 years ago

Enum Flags do not seem to work as expected. when using multiple flag bits, it deserializes the value to 0. Serialization works fine.

Test case below.

` using NUnit.Framework; using System;

[TestFixture]
public class NetJSONTests
{
    [Flags]
    public enum TestFlags
    {
        A = 1,
        B = 2,
        C = 4
    }

    public class FooA
    {
        public int Type
        { get; set; }

        public int IntVal
        { get; set; }

        public TestFlags EnumVal
        { get; set; }
    }

    [Test]
    public void TestEnumFlags()
    {
        var foob = new FooA
        {
            IntVal = 1,
            EnumVal = TestFlags.A | TestFlags.B,
            Type = 2
        };

        NetJSON.NetJSON.IncludeTypeInformation = true;
        var json = NetJSON.NetJSON.Serialize((FooA)foob);
        var obj = NetJSON.NetJSON.Deserialize<FooA>(json);

        Assert.AreEqual(obj.EnumVal, foob.EnumVal);
    }

} `

rpgmaker commented 7 years ago

Can you try passing netjsonsetting and use "enum string" property and see if it does preserve it? If it does, it might just be missing from the int version of enum only. I believe this was implement a long time ago. What version are you using?

Thanks,

rpgmaker commented 7 years ago

This issue seem to be similar with https://github.com/rpgmaker/NetJSON/issues/130 .

physhi commented 7 years ago

Even "UseEnumString" does not work. It Serializes enum just fine as string, but deserialization fails.

I'm using ver: v1.2.1.9, last updated Jan 30th from nuget.

rpgmaker commented 7 years ago

Please try it again. It should work now. Thanks again for the find