il2cpp and jsonFX problem!

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:

[SIZE=2]MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.ComponentModel.Int32Converter'.
  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
  at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
  at System.ComponentModel.TypeDescriptor.GetConverter (System.Type type) [0x00000] in <filename unknown>:0
  at JsonFx.Json.TypeCoercionUtility.CoerceType (System.Type targetType, System.Object value) [0x00000] in <filename unknown>:0
  at JsonFx.Json.JsonReader.ReadNumber (System.Type expectedType) [0x00000] in <filename unknown>:0
  at JsonFx.Json.JsonReader.Read (System.Type expectedType, Boolean typeIsHint) [0x00000] in <filename unknown>:0
  at JsonFx.Json.JsonReader.ReadObject (System.Type objectType) [0x00000] in <filename unknown>:0
  at JsonFx.Json.JsonReader.Read (System.Type expectedType, Boolean typeIsHint) [0x00000] in <filename unknown>:0
  at JsonFx.Json.JsonReader.Deserialize (Int32 start, System.Type type) [0x00000] in <filename unknown>:0
  at JsonFx.Json.JsonReader.Deserialize (System.String value, Int32 start, System.Type type) [0x00000] in <filename unknown>:0
  at TestJSON.TestJSONSerialize () [0x00000] in <filename unknown>:0
  at TestJSON.TestJSONSerialize () [0x00000] in <filename unknown>:0
  at TestJSON.Start () [0x00000] in <filename unknown>:0 [/SIZE]

This is TestJSON.cs script that I use for test

[SIZE=2]using UnityEngine;
using System.Collections;

using JsonFx.Json;

[SerializeField]
public class JSonTestClass
{
    public int indexInt;
    public float indexFloat;
    public string name;
    public int[] array;

    public string ToString()
    {
        return indexInt + " " + indexFloat + " " + name + " " + array.Length;
    }
}

public class TestJSON : MonoBehaviour
{
    void Start()
    {
        TestJSONSerialize ();
    }

    void TestJSONSerialize()
    {
        JSonTestClass jsonTest = new JSonTestClass();

        jsonTest.indexInt = 23;
        jsonTest.indexFloat = 95.12f;
        jsonTest.name = "testName";

        jsonTest.array = new int[5];
        for(int i = 0; i< 5; i++)
            jsonTest.array[i] = i;     

        string jsonString = JsonWriter.Serialize(jsonTest);
        Debug.Log(jsonString);
        JSonTestClass jSonDeseriazlie = JsonReader.Deserialize<JSonTestClass>(jsonString);
        Debug.Log("After Serialize " +  jSonDeseriazlie.ToString());
    }
}[/SIZE]

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)

I have the same problem.

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.

So are there alternatives to JsonFX? Any experiences?
Atm i’am trying Newtonsoft.Json.

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

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.

I think il2cpp is not support ā€˜Default constructor’

  • public class JSonTestClass
  • {
  • public int indexInt;
  • public float indexFloat;
  • public string name;
  • public int[ ] array;

public JSonTestClass() << explicit constructor
{
}

  • public string ToString()
  • {
  • return indexInt + " " + indexFloat + " " + name + " " + array.Length;
  • }
  • }
1 Like

@Dustin-Horne Perhaps you can add to this discussion?

1 Like

Thanks for answer!

But this is not a solution for this problem

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.

@Dustin-Horne
I’am not using the json serializer/deserializer from the asset store.
Thats what i tried.
https://json.codeplex.com/

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.

I try Json.Net, it works perfectly on iOS 64 bit with il2cpp, (small changes from Json syntax and all work again)

Thanks Dustin!

1 Like

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.

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.