fastJSON icon indicating copy to clipboard operation
fastJSON copied to clipboard

Parser not desterilizing nullable properties

Open Frankinstien4444 opened this issue 3 years ago • 3 comments

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; }

}`

Frankinstien4444 avatar Mar 12 '22 21:03 Frankinstien4444

What do you get?

mgholam avatar Mar 13 '22 06:03 mgholam

It deserializes as null.

Frankinstien4444 avatar Mar 15 '22 15:03 Frankinstien4444

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);
    }

mgholam avatar Mar 16 '22 09:03 mgholam