Serializing a Class with NativeHashMaps and NativeList to json and then Deserialzing back

Hi there,

Lets suppose i have a class with NativeHashMaps and NativeLists using persistent allocators. I want to serialize into json and then deseriazling back to this instancce which is already allocated like json.net PopulateObject.

I’m not using Entities, but using it in jobs.

So please how are you solving this case?
Thanks

If you’re using Json.Net create a custom converter for it? Custom JsonConverter

-edit- actually yeah snacktime makes a good point, if you’re doing this it’s clearly not performance critical so just copy it.

1 Like

If you are serializing to and back in a closed loop use the entities binary serialization. You would need to flatten your hashmap to an array but not a big deal.

Or just copy to managed Dictionary/List and back. Json is so slow that the cost of the copy isn’t going to be an issue.

1 Like

Actually i have to use JSON so i can save/load it in backend which expects a json, i have no issue with performance as its load one time and save when played turn
Currently im making another class which copy to managed and then serialize/deserialize with json.net but this feels “extra” work which i want to avoid.

1 Like