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] Exception: Expected digit #348

Open
Saibamen opened this issue Jun 10, 2021 · 2 comments
Open

[Deserialization] Exception: Expected digit #348

Saibamen opened this issue Jun 10, 2021 · 2 comments

Comments

@Saibamen
Copy link

This JSON can be deserialized by Newtonsoft.Json without any problems.

JSON:

{
   "MyString":"testString",
   "MyInt":5,
   "MyIntButStringInJson":"234"
}

Class:

public class TestJil
{
    public string MyString { get; set; }
    public int MyInt { get; set; }
    public int MyIntButStringInJson { get; set; }
}

Deserialization code:

var testJson = "{\r\n   \"MyString\":\"testString\",\r\n   \"MyInt\":5,\r\n   \"MyIntButStringInJson\":\"234\"\r\n}";

using (var input = new StringReader(testJson))
{
    var dupaTam = JSON.Deserialize<TestJil>(input);
}

Exception

Message = "Expected digit"

SnippetAfterError = "234\"\r\n}"

StackTrace:

at Jil.Deserialize.Methods._ReadInt32(TextReader reader)
at Jil.JSON.Deserialize[T](TextReader reader, Options options)

Jil version: 2.17.0

@lettywang
Copy link

Hi, Do u have a solution now? I encountered the same problem. It's not easy to replace with other serialize lib base on my project.

@tcsaddul
Copy link

I think there is something wrong with your code. Make sure the int property gets an int value. It would be an optimization blow to JIL for detecting and converting a string to int.

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

3 participants