Dictionary support for JsonUtility

I want to stop using the JsonDotNet library in favor of the new JsonUtility, but it seems to be missing the very important feature of serializing the generic Dictionary class. Any change that will one day be supported?

1 Like

Probably not any time soon, as we have to support it in the serialiser itself (i.e. In the Inspector, etc) before we can support it in JsonUtility. It’d also be difficult to make it fast.

Note that JsonUtility does support the ISerializationCallbackReceiver interface, though; if you want to pack stuff from/to a dictionary before/after serialisation, you can use it to do that.

Oh cool, I didn’t realize that was supported. Thanks!

I think I saw it somewhere else in these forums, but I’d be keen on a [SerializeAs(“fieldNameInJson”)] type attribute if it’s not already in the works. We’re more interested in how to read json data that we’re given (service responses) than using it for storing our own data. Dictionaries would be ideal but the attribute might be enough for us :slight_smile:

Yep, the ability to provide multiple source names and an alternative target name are high on my to-do list, as well as stuff like letting you make enums serialise as strings rather than numbers.

3 Likes

Awesome! Looking forward to seeing how this utility develops :slight_smile:

(For the curious: both features require that we can read attribute values from fields from C++. Currently, we can find out whether you have an attribute applied to a field from C++, but we can’t see what the values on it are without actually constructing the attribute object on the C# side, and that would generate a ton of garbage and be very slow. So, first step is actually for us to modify Mono and IL2CPP to let us retrieve the parameters you passed to the attribute directly from the assembly metadata).

4 Likes