Closed cubed-it closed 6 years ago
Thanks for the finding. Can you post your object class structure?
Thanks,
I have given the complete example above. It runs like this on LinqPad.
Sorry, I did not see it initially... thanks
What happens if you don't set A to null and use a specific instance?
It should be type B, instead of type A. I changed the example. Any way, it makes no difference whether it is a null or a concrete object. The concrete object is deserialized correct, just the key is a pure random value.
If I use a int as key and value, the value is deserialized correctly.
void Main()
{
var xy = new A();
xy.Details.Add(666, 777);
var json = NetJSON.NetJSON.Serialize(typeof(A), xy);
var obj = NetJSON.NetJSON.Deserialize<A>(json);
obj.Dump();
}
public class A
{
public A()
{
Details = new Dictionary<int, int>();
}
public Dictionary<int, int> Details { get; set; }
}
=> Key 74613460 Value 777
I see. I have never noticed the behavior before. What version are you using? The random value you are getting is the address at runtime that the int value points to before it is set. It looks like the key is not been read from the json even though it is supposed to be.
I will look into it tonight. Thanks for the details so far.
So far I used version 1.2.2. However, with version 1.2.3 I see no difference. I just replaced the key with a own object with an int id. Now I get a constant wrong result ;-) So e.g. key of new B() { Id = 666 } returns always B.Id with 11. ;-)
Would be great if this could be solved. However, thanks for the quick response!
Thank you so much for this find. I broke it and did not notice it, but now i have a basic test for it.
I also went ahead and publish the latest version.
Great! That was fast. Thank you very much!
Hey there,
I would like to deserialize a Dictionary. e.g. I serialize a key of 666, but netjson returns a random number e.g. 75082016 (it is every cycle a different key). Whats' going on here?