Skip to content
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

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

Open
Din-Wan opened this issue Jul 14, 2021 · 1 comment

Comments

@Din-Wan
Copy link

Din-Wan commented Jul 14, 2021

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants