mgholam / fastJSON

Smallest, fastest polymorphic JSON serializer
https://www.codeproject.com/Articles/159450/fastJSON-Smallest-Fastest-Polymorphic-JSON-Seriali
MIT License
479 stars 147 forks source link

Can not get the value after parse in the version 2.3.3 upper #132

Closed dungvu-equix closed 3 years ago

dungvu-equix commented 3 years ago

Dear support, I have a issue when try to update your lib from 2.3.1 to the latest version. My code is run in .net core 3.1/5.0

Here my test, if I use the 2.3.1 the function is OK, but upgrade it to newer versions, it always fail. Could you check it for me?

`using System; using fastJSON;

namespace Test { class Program { static void Main(string[] args) { var jsonObj = new ExtendMessage { Layer0 = LayerEnum.L0, Layer1 = LayerEnum.L1, Layer2 = LayerEnum.L2, Layer3 = LayerEnum.L3, Layer4 = LayerEnum.L4 }; //first try to parse this msg var stringJson = JSON.ToJSON(jsonObj); // and re-make the object with the base var testParse = JSON.ToObject(stringJson); // check the parser works if (testParse is ExtendMessage) { var obj = testParse as ExtendMessage; //check it have value if (obj.Layer4 == LayerEnum.L4) { Console.WriteLine("OK"); } else { // found issue in >>>>> HERE <<<<< Console.WriteLine("FAIL:" + obj.Layer4); } } else { Console.WriteLine("FAIL:" + stringJson); } Console.ReadLine(); } }

public enum LayerEnum
{
    NONE = 0,
    L0 = 1,
    L1 = 10,
    L2 = 20,
    L3 = 30,
    L4 = 40
}

public class ExtendMessage : Message
{
    public LayerEnum Layer4 { get; set; }
}

public class Message : BaseMessage
{
    public LayerEnum Layer3 { get; set; }
}

public class BaseMessage : AbstractMessage
{
    public LayerEnum Layer2 { get; set; }
}

public abstract class AbstractMessage
{
    public LayerEnum Layer1 { get; set; }
    public LayerEnum Layer0 { get; internal set; }
}

public interface IMessage
{
    LayerEnum Layer0 { get; set; }
}

}`

dungvu-equix commented 3 years ago

if you change to parse from the base class like: AbstractMessage, BaseMessage, Message... it will be the same behaviers, lost all the values.

mgholam commented 3 years ago

Your code works with v2.4.0.5

dungvu-equix commented 3 years ago

let me check, thank you