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

Boolean serializer incompatible with JavaScript eval #22

Closed
GoogleCodeExporter opened this issue May 19, 2015 · 2 comments
Closed

Boolean serializer incompatible with JavaScript eval #22

GoogleCodeExporter opened this issue May 19, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Create a class with a boolean property
2. Serialize an instance of the class to a JSON string
3. Call eval(JSON-string) in a browser

What is the expected output? What do you see instead?
It is expected that the eval method will convert the JSON string into
an object of type class. What happens instead is that the eval method 
throws an exception saying that the boolean value (True or False) is not 
valid. The reason the boolean value is not valid is that JavaScript 
expects a boolean value of all lower case "true" or "false" while the .Net 
framework (unlike every other framework in existence) returns a mixed 
case "True" or "False" value.

What version of the product are you using? On what operating system?
2.1.0.127

Please provide any additional information below.
The fix is to do the following:

In JsonWriter.cs, line 145 replace the method for writing a bool with this:

        public IJsonWriter Value(bool value)
        {
            PreWrite(OpType.OpValue);
            if (value)
            {
                _writer.Write(bool.TrueString.ToLower());
            }
            else
            {
                _writer.Write(bool.FalseString.ToLower());
            }
            return this;
        }

this will have the affect of taking the true and false values and writing 
them correctly to the JSON stream.

Original issue reported on code.google.com by clrg...@gmail.com on 18 Jul 2008 at 1:46

@GoogleCodeExporter
Copy link
Author

Duplicate of Issue 18

Original comment by elliott....@gmail.com on 18 Jul 2008 at 1:49

  • Changed state: Duplicate

@GoogleCodeExporter
Copy link
Author

Original comment by elliott....@gmail.com on 19 Jul 2008 at 4:24

  • Added labels: Milestone-Release2.1.1

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

No branches or pull requests

1 participant