I'm confused. I tried to save a current status of my game through Newtonsoft.JSON serialization. So far so good, it worked perfectly, I got a string containing all the information I need in json format. But when I try to deserialize it, the trouble comes in:
An unhandled exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
Additional information: Error converting value "{X:-32 Y:-32 Width:64 Height:64}" to type 'Microsoft.Xna.Framework.Rectangle'. Path 'GameElements[0].Hitbox', line 5, position 51.
When i click on details, it says "Cannot convert from System.String to Microsoft.XNA.Framework.Rectangle. But isn't that exactly the job of a json deserializer?
Thanks in advance, hope you have an idea what might be causing that.
PS: Code for deserializing:
JsonConvert.DeserializeObject<GameState>(
GameSettings.Default.SaveStates[name],
new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.Auto
});
Edit: Thanks for all the help, but turns out I'm just a derp... The rectangle I serialized was a Property without a setter. But I also want to turn out that json.net doesn't help with such an error in any meaningful way.
Edit2: Really interesting how XNA rectangles also cant be serialized even if they have a setter (duplicate-comment)...