-
Notifications
You must be signed in to change notification settings - Fork 202
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
Serialization/Deserialization Support (error using System.Text.Json.JsonSerializer) #275
Comments
you can use cjson in lua, i will use cjson to simple support System.Text.Json in future |
So recently I've developed more or less this functionality. You can find it on this repo https://github.com/Orden4/WCSharp. As of this writing, it's in the development branch in the WCSharp.Json folder, but it should be on the master within a few weeks. As said, it's still under development, as for one I'd like to add some basic error reporting, do some further robustness testing, and add some more comments. However, I believe the current version to already be feature complete to the full extent of my capabilities within CSharp.lua. Use is essentially like Newtonsoft.Json, in which you can just call
Additionally, much like Newtonsoft, besides being able to do e.g. Currently, this is implemented via a combination of C# code to do the type processing, and injected Lua code using https://github.com/rxi/json.lua to convert data into strings and back. As such it's a bit hacked together, as it's not written entirely in either C# nor Lua, but this was the easiest implementation I could think of that didn't involve me writing my own stringify code or doing it entirely in Lua. Anyway, feel free to do with this as you like. I wrote this to use in WarCraft 3, to allow custom maps to easily store data/send it between players, but I'd be happy if someone found a use for this elsewhere. |
Thank you very much for your code, and when I looked closely, I found that there was a difference in interface requirements with System.Text.Json.JsonSerializer that could not be used directly. |
I tried to use the following...
m_UnitInputData = System.Text.Json.JsonSerializer.Deserialize<InputData.Unit[]>(jsonStr);
But when compiled to lua, it gives an error:
attempt to index a nil value (upvalue 'SystemTextJson')
My understanding is that this indicates this functionality is not supported. Are there any alternate forms of serialization that are supported? Might I have more luck with the BinaryFormatter class? Or do I just need to find a different way to solve my problem than de-serializing data?
Also just for clarity, I am able to deserialize the same json str into the same types in a standalone c# console app.
The text was updated successfully, but these errors were encountered: