mgholam / fastJSON

Smallest, fastest polymorphic JSON serializer
https://www.codeproject.com/Articles/159450/fastJSON-Smallest-Fastest-Polymorphic-JSON-Seriali
MIT License
478 stars 148 forks source link

Parser not desterilizing nullable properties #136

Open Frankinstien4444 opened 2 years ago

Frankinstien4444 commented 2 years ago

When I use an ?int property the value does save to the file correctly but I'm not able to deserialize the value. Any ideas?

`[Serializable] public class ControllerAsset : AutoGeneratedNetworkDevice {

    [DataMember]

    public String Firmware { set; get; }

    [DataMember]

    public int? GroupID { set; get; }

}`
mgholam commented 2 years ago

What do you get?

Frankinstien4444 commented 2 years ago

It deserializes as null.

mgholam commented 2 years ago

The following works:

    public class ControllerAsset //: AutoGeneratedNetworkDevice
    {
        public String Firmware { set; get; }
        public int? GroupID { set; get; }
    }

    [Test]
    public static void nullabletest()
    {
        var c = new ControllerAsset { GroupID = 10 };
        var s = JSON.ToJSON(c);
        Console.WriteLine(s);
        var o = JSON.ToObject<ControllerAsset>(s);
        Assert.AreEqual(10,  o.GroupID);
    }