Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

il2cpp and jsonFX problem!

Discussion in 'Unity 5 Pre-order Beta' started by DziDAI, Jan 27, 2015.

  1. DziDAI

    DziDAI

    Joined:
    Dec 6, 2012
    Posts:
    68
    Hi All!

    How I understand all that works on mono, should work on il2cpp (I mean beck end mono and il2cpp)!

    But now I have a problems with JSOn deserialization, I use JsonFx, and all work fine if I set mono in backend,
    but when I set il2cpp I see in xCode console next message:

    Code (JavaScript):
    1.  
    2. [SIZE=2]MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.ComponentModel.Int32Converter'.
    3.   at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
    4.   at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
    5.   at System.ComponentModel.TypeDescriptor.GetConverter (System.Type type) [0x00000] in <filename unknown>:0
    6.   at JsonFx.Json.TypeCoercionUtility.CoerceType (System.Type targetType, System.Object value) [0x00000] in <filename unknown>:0
    7.   at JsonFx.Json.JsonReader.ReadNumber (System.Type expectedType) [0x00000] in <filename unknown>:0
    8.   at JsonFx.Json.JsonReader.Read (System.Type expectedType, Boolean typeIsHint) [0x00000] in <filename unknown>:0
    9.   at JsonFx.Json.JsonReader.ReadObject (System.Type objectType) [0x00000] in <filename unknown>:0
    10.   at JsonFx.Json.JsonReader.Read (System.Type expectedType, Boolean typeIsHint) [0x00000] in <filename unknown>:0
    11.   at JsonFx.Json.JsonReader.Deserialize (Int32 start, System.Type type) [0x00000] in <filename unknown>:0
    12.   at JsonFx.Json.JsonReader.Deserialize (System.String value, Int32 start, System.Type type) [0x00000] in <filename unknown>:0
    13.   at TestJSON.TestJSONSerialize () [0x00000] in <filename unknown>:0
    14.   at TestJSON.TestJSONSerialize () [0x00000] in <filename unknown>:0
    15.   at TestJSON.Start () [0x00000] in <filename unknown>:0 [/SIZE]
    16.  
    This is TestJSON.cs script that I use for test

    Code (CSharp):
    1.  
    2. [SIZE=2]using UnityEngine;
    3. using System.Collections;
    4.  
    5. using JsonFx.Json;
    6.  
    7. [SerializeField]
    8. public class JSonTestClass
    9. {
    10.     public int indexInt;
    11.     public float indexFloat;
    12.     public string name;
    13.     public int[] array;
    14.  
    15.     public string ToString()
    16.     {
    17.         return indexInt + " " + indexFloat + " " + name + " " + array.Length;
    18.     }
    19. }
    20.  
    21. public class TestJSON : MonoBehaviour
    22. {
    23.     void Start()
    24.     {
    25.         TestJSONSerialize ();
    26.     }
    27.  
    28.     void TestJSONSerialize()
    29.     {
    30.         JSonTestClass jsonTest = new JSonTestClass();
    31.  
    32.         jsonTest.indexInt = 23;
    33.         jsonTest.indexFloat = 95.12f;
    34.         jsonTest.name = "testName";
    35.  
    36.         jsonTest.array = new int[5];
    37.         for(int i = 0; i< 5; i++)
    38.             jsonTest.array[i] = i;    
    39.  
    40.         string jsonString = JsonWriter.Serialize(jsonTest);
    41.         Debug.Log(jsonString);
    42.         JSonTestClass jSonDeseriazlie = JsonReader.Deserialize<JSonTestClass>(jsonString);
    43.         Debug.Log("After Serialize " +  jSonDeseriazlie.ToString());
    44.     }
    45. }[/SIZE]
    46.  
    Is it Bug or not?

    If I right understand about il2cpp, if code work with mono backEnd, this code also MUST work with il2cpp right?

    (Bug with Case Number:667196)
     
    Last edited: Jan 27, 2015
  2. Chris333

    Chris333

    Joined:
    Dec 15, 2014
    Posts:
    13
    I have the same problem.
     
  3. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    Wrong. Not everything that works on mono works with IL2CPP.

    IL2CPP is AOT only and in your case JsoxFX is known to work badly on iOS (AOT platform) because it uses JIT features so it wont probably work well with IL2CPP either unless there is an updated version out there.
     
  4. Chris333

    Chris333

    Joined:
    Dec 15, 2014
    Posts:
    13
    So are there alternatives to JsonFX? Any experiences?
    Atm i'am trying Newtonsoft.Json.
     
  5. DziDAI

    DziDAI

    Joined:
    Dec 6, 2012
    Posts:
    68
    I'am looking on Json.Net, but I'am not sure about equal functionality like in JsonFX i.e Generic lists serialize deserialize and etc
     
  6. Chris333

    Chris333

    Joined:
    Dec 15, 2014
    Posts:
    13
    Newtonsoft.Json does also not work. It gives me also an error.
    @DziDAI Does it also not work for you?

    I'am using now the JSONObject from the wiki with a custom deserializer for my datastructure.
    http://wiki.unity3d.com/index.php/Json
    Its a very bad solution for me because if the datastructure changes i have always to change the deserializer too.
     
  7. Dlswjfal

    Dlswjfal

    Joined:
    Jan 28, 2015
    Posts:
    2
    I think il2cpp is not support 'Default constructor'

    1. public class JSonTestClass
    2. {
    3. public int indexInt;
    4. public float indexFloat;
    5. public string name;
    6. public int[] array;
    public JSonTestClass() << explicit constructor
    {
    }
    1. public string ToString()
    2. {
    3. return indexInt + " " + indexFloat + " " + name + " " + array.Length;
    4. }
    5. }
     
    abertrand likes this.
  8. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    Dustin-Horne likes this.
  9. DziDAI

    DziDAI

    Joined:
    Dec 6, 2012
    Posts:
    68
    Thanks for answer!

    But this is not a solution for this problem
     
  10. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    I haven't looked at jsonfx so I'm not sure why it wouldn't work. However, my json .net for unity asset does work as of unity 5 beta 20 and the newest 4.6 patch release.

    What platform are you building for? I'm assuming by newtonsoft you guys mean my port and not the official. If its ios64-bit it should just work. If its webgl, send me a pm with your invoice number and ill send you an update with the proper directives for webgl.
     
  11. Chris333

    Chris333

    Joined:
    Dec 15, 2014
    Posts:
    13
  12. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Ahh yeah that will never work. It's not aot compatible. In fact it wont work with anything except desktop standalone builds and in the editor. That's why I made the port.
     
  13. DziDAI

    DziDAI

    Joined:
    Dec 6, 2012
    Posts:
    68
    I try Json.Net, it works perfectly on iOS 64 bit with il2cpp, (small changes from Json syntax and all work again)

    Thanks Dustin!
     
    Quaker_SDR likes this.
  14. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    You're version y welcome. :). I am still seeing a couple il2cpp bugs and having people submit bug reports, bit so far it's looking good.
     
  15. SunstormJared

    SunstormJared

    Joined:
    Jan 30, 2013
    Posts:
    4
    Our problem with the "Default constructor not found...ctor()" was solved with a slight code adjustment. So while switching JSON libraries might work for some (who have a budget and time to do so...), hopefully others will find our solution viable.

    Our issue was that the System. Activator.CreateInstance function was failing to find a default constructor for an array of custom class. This was solved by swapping references to System. Activator.CreateInstance with references to System.Array.CreateInstance and passing the ElementType instead of the Type. An array of the correct type was then created, and populated with our data from JSON just like when we compiled with Mono. Additionally, this solution worked for us within Mono compiler and within the IL2CPP so for any struggling with Abstracted Types and JSON parsing; there is a solution.