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

Deserialization fails (or is incorrect) for classes which contain Nullable<> or ? #46

Closed
Villenny opened this issue Mar 14, 2015 · 3 comments
Assignees
Labels

Comments

@Villenny
Copy link

    public class TestMe
    {
        public string a { get; set; }
        public string b { get; set; }
        public int? c { get; set; }
        public int? d { get; set; }
    }

                var testMe = new TestMe
                {
                    a = "Test",
                    c = 0
                };
                if (useNetJSON == true)
                {
                    vals[j] = NetJSON.NetJSON.Serialize(testMe);
                    var obj = NetJSON.NetJSON.Deserialize(typeof(TestMe), vals[j]);
                    testMe = (TestMe)obj;
                }

afterwards in the new testMe object c will be null rather than 0.

@rpgmaker
Copy link
Owner

It is not really a bug. It does that because the default value of int is
zero. And since NetJSON.SkipDefault is set to true it will not set the
value because zero is considered the default. The fix is either set the
flag to false or I can simple ignore the flag for nullable types.
On Mar 13, 2015 9:21 PM, "Villenny" notifications@github.com wrote:

public class TestMe
{
    public string a { get; set; }
    public string b { get; set; }
    public int? c { get; set; }
    public int? d { get; set; }
}

            var testMe = new TestMe
            {
                a = "Test",
                c = 0
            };
            if (useNetJSON == true)
            {
                vals[j] = NetJSON.NetJSON.Serialize(testMe);
                var obj = NetJSON.NetJSON.Deserialize(typeof(TestMe), vals[j]);
                testMe = (TestMe)obj;
            }

afterwards in the new testMe object c will be null rather than 0.


Reply to this email directly or view it on GitHub
#46.

@Villenny
Copy link
Author

I would consider it a bug myself.

The default for int is 0
the default for int? (ie Nullable) is null. (In fact the default of
Nullable is always null)

hence the problem, you must stream Nullable if its non default (ie non
null). Once you do everything should work properly.

thanks.
Ryan

On Fri, Mar 13, 2015 at 6:43 PM, Rpgmaker notifications@github.com wrote:

It is not really a bug. It does that because the default value of int is
zero. And since NetJSON.SkipDefault is set to true it will not set the
value because zero is considered the default. The fix is either set the
flag to false or I can simple ignore the flag for nullable types.
On Mar 13, 2015 9:21 PM, "Villenny" notifications@github.com wrote:

public class TestMe
{
public string a { get; set; }
public string b { get; set; }
public int? c { get; set; }
public int? d { get; set; }
}

var testMe = new TestMe
{
a = "Test",
c = 0
};
if (useNetJSON == true)
{
vals[j] = NetJSON.NetJSON.Serialize(testMe);
var obj = NetJSON.NetJSON.Deserialize(typeof(TestMe), vals[j]);
testMe = (TestMe)obj;
}

afterwards in the new testMe object c will be null rather than 0.


Reply to this email directly or view it on GitHub
#46.


Reply to this email directly or view it on GitHub
#46 (comment).

@rpgmaker
Copy link
Owner

Yep you are correct it is a bug that needs to be fixed.

Thanks,
On Mar 14, 2015 12:35 AM, "Villenny" notifications@github.com wrote:

I would consider it a bug myself.

The default for int is 0
the default for int? (ie Nullable) is null. (In fact the default of
Nullable is always null)

hence the problem, you must stream Nullable if its non default (ie non
null). Once you do everything should work properly.

thanks.
Ryan

On Fri, Mar 13, 2015 at 6:43 PM, Rpgmaker notifications@github.com
wrote:

It is not really a bug. It does that because the default value of int is
zero. And since NetJSON.SkipDefault is set to true it will not set the
value because zero is considered the default. The fix is either set the
flag to false or I can simple ignore the flag for nullable types.
On Mar 13, 2015 9:21 PM, "Villenny" notifications@github.com wrote:

public class TestMe
{
public string a { get; set; }
public string b { get; set; }
public int? c { get; set; }
public int? d { get; set; }
}

var testMe = new TestMe
{
a = "Test",
c = 0
};
if (useNetJSON == true)
{
vals[j] = NetJSON.NetJSON.Serialize(testMe);
var obj = NetJSON.NetJSON.Deserialize(typeof(TestMe), vals[j]);
testMe = (TestMe)obj;
}

afterwards in the new testMe object c will be null rather than 0.


Reply to this email directly or view it on GitHub
#46.


Reply to this email directly or view it on GitHub
#46 (comment).


Reply to this email directly or view it on GitHub
#46 (comment).

@rpgmaker rpgmaker self-assigned this Mar 15, 2015
@rpgmaker rpgmaker added the bug label Mar 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants