Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser not desterilizing nullable properties #136

Open
Frankinstien4444 opened this issue Mar 12, 2022 · 3 comments
Open

Parser not desterilizing nullable properties #136

Frankinstien4444 opened this issue Mar 12, 2022 · 3 comments

Comments

@Frankinstien4444
Copy link

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
Copy link
Owner

mgholam commented Mar 13, 2022

What do you get?

@Frankinstien4444
Copy link
Author

It deserializes as null.

@mgholam
Copy link
Owner

mgholam commented Mar 16, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants