rpgmaker / NetJSON

Faster than Any Binary? Benchmark: http://theburningmonk.com/2014/08/json-serializers-benchmarks-updated-2/
MIT License
231 stars 29 forks source link

Deserialization mistake of boolean value #203

Closed hhblaze closed 6 years ago

hhblaze commented 6 years ago

NetJSON versions 1.2.7 Object can be deserialized but shows incorrect boolean value.

File netjson.txt contains generated (by NetJSON) a JSON-string - serialized object YadroUser from attached file netjsonObj.txt.

Reproducing:

var usr = NetJSON.NetJSON.Deserialize<TEST.YadroUser>(File.ReadAllText(@"D:\Temp\1\netjson.txt"));

Value "Enabled" after deserialization is true, though must be false.

netjson.txt netjsonObj.txt

rpgmaker commented 6 years ago

In looking at your object. You don't have "Enabled" in your netjson.txt string. And since you have a constructor that initialize the YadroUser object which set Enabled = true. It will be true by default.

Since this is the step that occurs during deserialization.

hhblaze commented 6 years ago

Thanx, I see that....was a bit overloaded.... it's xml tag... closing the issue

rpgmaker commented 6 years ago

Np. 👍

hhblaze commented 6 years ago

In total this problem appeared, because default boolean (and probably other types) value is not storing together with the JSON object. I couldn't implement the idea that after initializing class YadroUser (from NetJsonObj.txt) the default value for "Enabled" must be set to true, by setting it up in constructor. It was set to "Enabled"= false within the program and saved without that JSON property. On reading from DB it was set to "True" value and not overriden with false, because there was no such JSON property. Very unhandy. Probably, there should be (or there is) a NetJSON flag that tells to store all values, even default? In my case disk space doesn't play much role, so I would use that. More of it, IMHO, this option must be set by default to "full-save".

rpgmaker commented 6 years ago

The option to not skip default exists. Here https://github.com/rpgmaker/NetJSON/wiki/Quick-Guide .

You need to set skipDefualt to false in the settings object.

Thanks,

hhblaze commented 6 years ago

Mystical persecution continues: now I got following object (see attached files netjson.txt netjsonObj.txt

) and while deserialization I still have "Enabled" = true

rpgmaker commented 6 years ago

I will look into it.

Thanks,

rpgmaker commented 6 years ago

It is fixed. I will create a new nuget package once i fix the other two issues. Thanks

rpgmaker commented 6 years ago

It is published on nuget and should be available soon.

hhblaze commented 6 years ago

Very nice, thank you!