Custom JSON converters inside project should be isolated
I have a rather big project and use JSON.net for other purposes as well and I am using other custom converters for Unity standard types (vector2/3...). I'd assume most big project do so. The thing is, that the converters are not compatible and I had to manually isolate the converters now between the calls.
I recommend to do so per default in GLTF. Here my changes to the importer class:
- Declare used converters on top:
public static class Importer { // only use specified converters to ensure consistent file format private static readonly List<JsonConverter> JSON_CONVERTERS = new List<JsonConverter> { new StringEnumConverter(), new KeyValuePairConverter(), new BinaryConverter(), new ColorRGBConverter(), new ColorRGBAConverter(), new EnumConverter(), new Matrix4x4Converter(), new QuaternionConverter(), new TranslationConverter(), new Vector2Converter(), new Vector3Converter() };
public static JsonSerializerSettings GetDefaultJsonSettings()
{
return new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
Converters = JSON_CONVERTERS
};
}
-
Use settings in each deserialization
GLTFObject gltfObject = JsonConvert.DeserializeObject<GLTFObject>(json, GetDefaultJsonSettings());