applejag / Newtonsoft.Json-for-Unity.Converters

Converters of common Unity types for Newtonsoft.Json. Goes hand in hand with jilleJr/Newtonsoft.Json-for-Unity
https://github.com/jilleJr/Newtonsoft.Json-for-Unity.Converters
MIT License
332 stars 37 forks source link

Failing to deserialize due to reference IDs on serialized UnityEngine.Color #57

Open Din-Wan opened 3 years ago

Din-Wan commented 3 years ago

Hi! I hope I'm posting this in the right place... I am currently having a teeny problem with deserializing some JSON in my project. Originally, my project was using JSON .NET for Unity plugin by ParentElement, and so I have a lot of files which contain JSON that was created using their serializer. They were created with the following settings: var settings = new JsonSerializerSettings() { PreserveReferencesHandling = PreserveReferencesHandling.Objects };

The object I serialized contained UnityEngine.Color and the resulting JSON contained $id metadata for the Colors. However, when I used your serializer with the converter and the same ReferenceHandling settings, $id tags are not generated for the Colors. The problem I am having is when I try to deserialize the existing JSON in my project, I get the following error:

Newtonsoft.Json.JsonSerializationException : Unexpected token while deserializing object: PropertyName. Path 'Path.To.Property.After.Color'

If it helps, here is the class containing the Color:

[JsonObject(MemberSerialization = MemberSerialization.Fields)]
public class Style
{
  ...
  private Color32 color;
  public Color Color { get; set; }
  ...
}

I was wondering you might know what's going wrong and of any way of dealing with this issue. Thanks in advance.

applejag commented 3 years ago

Hello!

My custom converts does not support the different JsonSerializerSettings as I've intentionally not considered them. The UnityEngine.Color and UnityEngine.Color32 types are structs, and so there should be no use for having $id references between them.

I'll try to reproduce this and take a closer look, because you should not get an error like that either case.