mgholam / fastJSON

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

Feature Request: Support IL2CPP - AOT for JSON.ToObject #102

Open xmedeko opened 5 years ago

xmedeko commented 5 years ago

When using IL2CPP compiler (AOT - Ahead Of Time), then JSON.ToObject fails with: System.NotSupportedException: System.Reflection.Emit.DynamicMethod::.ctor.

This is a problem for platforms like Unity3D, Xamarin and others, see #46, #49, #60

The problem is, the DynamicMethod must not be used in the Reflection. Please, make some switch (e.g. #if ENABLE_IL2CPP) to have working Reflection for IL2CPP, too.

I've made a fork to fix this issue https://github.com/xmedeko/UnityFastJSON but the code may not be optimal. Use the last commit in the repo only.

Also, user @iodev has made the changes a while ago, see the fork https://github.com/iodev/fastJSON/tree/master/fastJSON%20UWP but it seems unfinished.

mgholam commented 4 years ago

Not using Reflection.Emit just nullifies the performance on restricted platforms. I don't have a fast option for this.

xmedeko commented 4 years ago

I understand that the solution is slower, but I prefer to have at least some working solution for more platforms event it would be slower on some platforms. IMHO if you put some warning into the project documentation, that the performance is degraded on IL2CPP platforms, then it's OK.

HydraOrc commented 3 years ago

+1 for the request, I am using a library that has fastJSON as dependency and Google Play Android Store requires x64 builds, which can only be built with il2cpp scripting backend. Will try the solution by xmedeko, hope it works.

wiverson commented 3 years ago

FYI/FWIW I was able to successfully use CSV parsing with Unity IL2CPP by manually binding instead of using reflection. It was a bit more work but once it was done it worked great. My entire game is built on top of CSV files.

mgholam commented 3 years ago

FYI/FWIW I was able to successfully use CSV parsing with Unity IL2CPP by manually binding instead of using reflection. It was a bit more work but once it was done it worked great. My entire game is built on top of CSV files.

So cool...