LitJSON / litjson

JSON library for the .Net framework
https://litjson.net/
Other
1.36k stars 403 forks source link

JsonData corrupts empty objects & arrays #128

Open discordgr opened 2 years ago

discordgr commented 2 years ago

I'm not sure how to properly explain the issue i have, so i'm gonna type an example. I have a generic json response, that i break it down to a class using JsonMapper.ToObject<Response>(response)

    public class Response{
        public JsonData data {get; set;},
        public int status {get; set;}
    }

After this class, data can break down to different types of objects depending on the response.

And i want to be able to map it again with: JsonMapper.ToObject<MyClass>(myResponse.data.ToJson())

The issue here is that if within JsonData there was an empty object or an empty array, the property is corrupted and instead being like this: "array" : [], it is like this: "array" : and i get a KeyNotFoundException.

Is there any workaround for this? Am i doing something wrong?