Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hikaripro opened this issue Oct 7, 2021 · 0 comments
Open

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

hikaripro opened this issue Oct 7, 2021 · 0 comments

Comments

@hikaripro
Copy link

Dear support,

With example dungvu-qe in issuess : #132

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?

Example :

static class Program
{
private static bool _isTestJson = true;
///


/// The main entry point for the application.
///

static void Main()
{
var directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string pathToExe = directory + "\fastJSON.dll";
//var fileInfo = new FileInfo(pathToExe);
var versionInfo = FileVersionInfo.GetVersionInfo(pathToExe);
string version = versionInfo.FileVersion;
Console.WriteLine("Start test FastJson: " + version);
TestEnumJson.RunTestCase();
Console.ReadLine();
}
}

namespace QuantEdge.Worker.TestFastJsonNetCore.Runner
{
public class TestEnumJson
{
public static void RunTestCase()
{
Console.WriteLine("Start run test case");
var obj = new ExtendMessage()
{
Layer1 = LayerEnum.L1,
Layer2 = LayerEnum.L2,
Layer3 = LayerEnum.L3,
Layer4 = LayerEnum.L4,
};
var lstObj = new List();
lstObj.Add(obj);
lstObj.Add(obj);

        Console.WriteLine("----------------TEST CASE 1--------------------------");
        var stringJson = JSON.ToJSON(obj);
        Console.WriteLine("stringJson: " + stringJson);
        ParseTo_BaseMessage(stringJson);
        ParseTo_AbstractMessage(stringJson);

        Console.WriteLine("----------------TEST CASE 2--------------------------");
        var stringJsonList = JSON.ToJSON(lstObj);
        Console.WriteLine("stringJsonList: " + stringJsonList);
        ParseTo_ListBaseMessage(stringJsonList);
        ParseTo_ListAbstractMessage(stringJsonList);
        ParseTo_DefaultList(stringJsonList);

        Console.ReadLine();
    }

    private static void ParseTo_BaseMessage(string stringJson)
    {
        Console.WriteLine("-------TEST : ");
        Console.WriteLine("Deserialize msg to : BaseMessage");
        var objParse = JSON.ToObject<BaseMessage>(stringJson);
        CheckMsg(objParse);
    }

    private static void ParseTo_AbstractMessage(string stringJson)
    {
        Console.WriteLine("-------TEST : ");
        Console.WriteLine("Deserialize msg to : AbstractMessage");
        var objParse = JSON.ToObject<AbstractMessage>(stringJson);
        CheckMsg(objParse);
    }

    private static void ParseTo_ListBaseMessage(string stringJson)
    {
        Console.WriteLine("-------TEST : ");
        Console.WriteLine("Deserialize msg to : List<BaseMessage>");
        var objParse = JSON.ToObject<List<BaseMessage>>(stringJson);
        if (objParse != null)
        {
            for (int i = 0; i < objParse.Count; i++)
            {
                var objCheck = objParse[i];
                CheckMsg(objCheck);
            }
        }
    }

    private static void ParseTo_ListAbstractMessage(string stringJson)
    {
        Console.WriteLine("-------TEST : ");
        Console.WriteLine("Deserialize msg to : List<AbstractMessage>");
        var objParse = JSON.ToObject<List<AbstractMessage>>(stringJson);
        if (objParse != null)
        {
            for (int i = 0; i < objParse.Count; i++)
            {
                var objCheck = objParse[i];
                CheckMsg(objCheck);
            }
        }
    }

    private static void ParseTo_DefaultList(string stringJson)
    {
        Console.WriteLine("-------TEST : ");
        Console.WriteLine("Deserialize msg to : DefaultList");
        var objParse = JSON.ToObject(stringJson);
        if (objParse is List<ExtendMessage>)
        {
            Console.WriteLine("objParse is List<ExtendMessage>");
            var lstMsg = (List<ExtendMessage>)objParse;
            for (int i = 0; i < lstMsg.Count; i++)
            {
                var objCheck = lstMsg[i];
                CheckMsg(objCheck);
            }
        }
        else if (objParse is List<object>)
        {
            Console.WriteLine("objParse is List<object>");
            var lstMsg = (List<object>)objParse;
            for (int i = 0; i < lstMsg.Count; i++)
            {
                var objCheck = (ExtendMessage)lstMsg[i];
                CheckMsg(objCheck);
            }
        }
        else
        {
            Console.WriteLine("objParse not is List<ExtendMessage>");
        }
    }

    private static void CheckMsg(object testParse)
    {
        if (testParse is ExtendMessage)
        {
            var obj = testParse as ExtendMessage;

            //check it have value
            if (obj.Layer1 == LayerEnum.L1 &&
                obj.Layer2 == LayerEnum.L2 &&
                obj.Layer3 == LayerEnum.L3 &&
                obj.Layer4 == LayerEnum.L4)
            {
                Console.WriteLine("------------------------------OK");
            }
            else
            {
                // found issue in >>>>> HERE <<<<<
                Console.WriteLine("------------------------------FAIL:");
            }
            LogTo.Info("obj.Layer0 = " + obj.Layer0);
            LogTo.Info("obj.Layer1 = " + obj.Layer1);
            LogTo.Info("obj.Layer2 = " + obj.Layer2);
            LogTo.Info("obj.Layer3 = " + obj.Layer3);
            LogTo.Info("obj.Layer4 = " + obj.Layer4);
        }
        else
        {
            Console.WriteLine("Message is not 'ExtendMessage'");
            Console.WriteLine("------------------------------FAIL:");
        }
    }

}


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; }
}

}

Result use fastjson ver 2.3.1 :

Start test FastJson: 2.2.0.0
Start run test case
----------------TEST CASE 1--------------------------
stringJson: {"$types":{"QuantEdge.Worker.TestFastJsonNetCore.Runner.ExtendMessage, TestFastJsonNetCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null":"1"},"$type":"1","Layer4":"L4","Layer3":"L3","Layer2":"L2","Layer1":"L1","Layer0":"NONE"}
-------TEST :
Deserialize msg to : BaseMessage
------------------------------OK
2021/10/07 14:44:40.172 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:44:40.199 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:44:40.199 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:44:40.199 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:44:40.199 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4
-------TEST :
Deserialize msg to : AbstractMessage
------------------------------OK
2021/10/07 14:44:40.199 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:44:40.199 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:44:40.199 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:44:40.199 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:44:40.199 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4
----------------TEST CASE 2--------------------------
stringJsonList: [{"$type":"QuantEdge.Worker.TestFastJsonNetCore.Runner.ExtendMessage, TestFastJsonNetCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","Layer4":"L4","Layer3":"L3","Layer2":"L2","Layer1":"L1","Layer0":"NONE"},{"$type":"QuantEdge.Worker.TestFastJsonNetCore.Runner.ExtendMessage, TestFastJsonNetCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","Layer4":"L4","Layer3":"L3","Layer2":"L2","Layer1":"L1","Layer0":"NONE"}]
-------TEST :
Deserialize msg to : List
------------------------------OK
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4
------------------------------OK
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4
-------TEST :
Deserialize msg to : List
------------------------------OK
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:44:40.207 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4
------------------------------OK
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4
-------TEST :
Deserialize msg to : DefaultList
objParse is List
------------------------------OK
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4
------------------------------OK
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:44:40.222 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4

--> in ver 2.2.0.0 allways OK

Result use fastjson ver 2.4.0.5 :

Start test FastJson: 2.4.0.5
Start run test case
----------------TEST CASE 1--------------------------
stringJson: {"$types":{"QuantEdge.Worker.TestFastJsonNetCore.Runner.ExtendMessage, TestFastJsonNetCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null":"1"},"$type":"1","Layer4":"L4","Layer3":"L3","Layer2":"L2","Layer1":"L1","Layer0":"NONE"}
-------TEST :
Deserialize msg to : BaseMessage
------------------------------OK
2021/10/07 14:47:05.788 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:47:05.814 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:47:05.814 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:47:05.814 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:47:05.814 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4
-------TEST :
Deserialize msg to : AbstractMessage
------------------------------OK
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4
----------------TEST CASE 2--------------------------
stringJsonList: [{"$type":"QuantEdge.Worker.TestFastJsonNetCore.Runner.ExtendMessage, TestFastJsonNetCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","Layer4":"L4","Layer3":"L3","Layer2":"L2","Layer1":"L1","Layer0":"NONE"},{"$type":"QuantEdge.Worker.TestFastJsonNetCore.Runner.ExtendMessage, TestFastJsonNetCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","Layer4":"L4","Layer3":"L3","Layer2":"L2","Layer1":"L1","Layer0":"NONE"}]
-------TEST :
Deserialize msg to : List
------------------------------FAIL:
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = NONE
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = NONE
------------------------------FAIL:
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:47:05.816 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = NONE
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = NONE
-------TEST :
Deserialize msg to : List
------------------------------FAIL:
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = NONE
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = NONE
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = NONE
------------------------------FAIL:
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = NONE
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = NONE
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = NONE
-------TEST :
Deserialize msg to : DefaultList
objParse is List
------------------------------OK
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:47:05.832 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:47:05.847 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:47:05.847 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4
------------------------------OK
2021/10/07 14:47:05.847 Method: 'Void CheckMsg(Object)'. Line: ~137. obj.Layer0 = NONE
2021/10/07 14:47:05.847 Method: 'Void CheckMsg(Object)'. Line: ~138. obj.Layer1 = L1
2021/10/07 14:47:05.847 Method: 'Void CheckMsg(Object)'. Line: ~139. obj.Layer2 = L2
2021/10/07 14:47:05.847 Method: 'Void CheckMsg(Object)'. Line: ~140. obj.Layer3 = L3
2021/10/07 14:47:05.847 Method: 'Void CheckMsg(Object)'. Line: ~141. obj.Layer4 = L4

--> Please help me fix issues when case use ver 2.4.0.5
Deserialize msg to : List not get all values
Deserialize msg to : List not get all values

Example attack : TestFastJsonNetCore.zip

Thank for support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant