Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

4.6.2 Newtonsoft Deserialization Problem

Discussion in 'iOS and tvOS' started by Jack-Yee, Feb 3, 2015.

  1. Jack-Yee

    Jack-Yee

    Joined:
    Sep 7, 2013
    Posts:
    7
    Hello,

    We've been testing Unity 4.6.2 and encountered a deserialization bug that we'd like to know if is occurring for anyone else.

    It's a simple case of serializing and deserializing a simple class that contains a string. It seems that the deserialized data is always NULL.

    Author of the serialization library noted that any issues that he's heard about have been in IL2CPP and have been actively fixing them. Would like to know if anyone else has been having this issue with this simple case.

    Thank you!

    Jack



    Here's the code:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using Newtonsoft.Json;
    public class Test : MonoBehaviour {
    public class MyData
    {
    public string name;
    }
    // Use this for initialization
    void Start () {
    MyData[] testData = new MyData[3];
    testData[0] = new MyData();
    testData[0].name = "aaa";
    testData[1] = new MyData();
    testData[1].name = "bbb";
    testData[2] = new MyData();
    testData[2].name = "ccc";
    string result = JsonConvert.SerializeObject(testData);
    Debug.Log("json:" + result);
    MyData[] convertedData = JsonConvert.DeserializeObject<MyData[]>(result);
    for (int i = 0 ; i < convertedData.Length ; ++i)
    Debug.Log("data(" + i + "):" + convertedData.name);
    }

    // Update is called once per frame
    void Update () {

    }

    }

    And here is the resulting output:

    Initialize engine version: 4.6.2f1 (bd99309c2ad7)

    Mono Class HideInInspector couldn't be found! This might lead to random crashes later on!


    (Filename: Line: 114)


    Unable to find type [UnityEngine.dll]UnityEngine.ResourceRequest


    (Filename: Line: 34)


    json:[{"tracks":null,"name":"aaa"},{"tracks":null,"name":"bbb"},{"tracks":null,"name":"ccc"}]

    Replacements.Attribute:CheckParameters(Object, Type)

    UnityEngine.Debug:Internal_Log(Int32, String, Object)

    UnityEngine.Debug:Log(Object)

    Test:Start()

    Replacements.Attribute:CheckParameters(Object, Type)


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/iPhonePlayer-armv7-il2cppGenerated/UnityEngineDebug.cpp Line: 56)


    data(0):

    Replacements.Attribute:CheckParameters(Object, Type)

    UnityEngine.Debug:Internal_Log(Int32, String, Object)

    UnityEngine.Debug:Log(Object)

    Test:Start()

    Replacements.Attribute:CheckParameters(Object, Type)


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/iPhonePlayer-armv7-il2cppGenerated/UnityEngineDebug.cpp Line: 56)


    data(1):

    Replacements.Attribute:CheckParameters(Object, Type)

    UnityEngine.Debug:Internal_Log(Int32, String, Object)

    UnityEngine.Debug:Log(Object)

    Test:Start()

    Replacements.Attribute:CheckParameters(Object, Type)


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/iPhonePlayer-armv7-il2cppGenerated/UnityEngineDebug.cpp Line: 56)


    data(2):

    Replacements.Attribute:CheckParameters(Object, Type)

    UnityEngine.Debug:Internal_Log(Int32, String, Object)

    UnityEngine.Debug:Log(Object)

    Test:Start()

    Replacements.Attribute:CheckParameters(Object, Type)


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/iPhonePlayer-armv7-il2cppGenerated/UnityEngineDebug.cpp Line: 56)

     

    Attached Files:

    vexe likes this.
  2. Jack-Yee

    Jack-Yee

    Joined:
    Sep 7, 2013
    Posts:
    7
    Sorry, the log that I attached may not match the sample program, but the results are the same. Trying to access string "name" in class MyData displays an empty string.

    Jack
     
  3. Jack-Yee

    Jack-Yee

    Joined:
    Sep 7, 2013
    Posts:
    7
    Discovered that if we used a List instead of array then it deserialized correctly.

    Thanks.

    Jack
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,491
    Hi,

    could you file a bug with a repro project? Your script depends on Newtonsoft.Json, and there's loads of different versions out there.
     
  5. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    He is using my asset. Collections seem to be a problem for il2cpp still. Arrays and multidimensional arrays fail to deserialize. Also, LinkedList<T> fails on the call to MakeGenericType. These all work fine when targeting mono, even on IOS, but when switching to il2cpp fail. The code in my asset that executes is exactly the same for both when building for IOS.
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,491
    Do we have a bug report on that? I remember investigating something related, but I think that was closed as resolved.
     
  7. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Probably not. I asked him to submit one so ill check but this was just yesterday so less than 24 hours ago. He replaced his linked list with a multidimensional array and had the same result as Jack.
     
  8. Jack-Yee

    Jack-Yee

    Joined:
    Sep 7, 2013
    Posts:
    7
    Hi folks,

    Update -- it is Case 669523

    I just submitted a simple test case using the Bug Reporter. It includes Dustin's JSON serialisation asset that we are using.



    Let me know if you need any more information. Thanks!

    Jack
     
    Dustin-Horne likes this.
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,491
    Thanks, we'll look into it.
     
  10. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Thanks Tautvydas. If you need me to get you specific repros put together for anything let me know and I'd be happy to put some together.
     
  11. vexe

    vexe

    Joined:
    May 18, 2013
    Posts:
    644
    Interesting. I've also got a user having some similar issues (List<List<Class>>). (I use FullSerializer as my backend) - He downgraded to 4.6.1 and the issues disappeared. So it's definitely a Unity thing, and not related to custom serializers.
     
  12. adampound

    adampound

    Joined:
    Jul 14, 2014
    Posts:
    28
    was this ever fixed?
     
  13. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Not sure. I should put together some additional tests. There are still some unresolved IL2CPP issues that I need to get bugs submitted for but not sure on this particular one.
     
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,491
    The bug in question was marked/confirmed as fixed a couple of months ago.
     
    Dustin-Horne likes this.