icubilla / jsonexserializer

Automatically exported from code.google.com/p/jsonexserializer
0 stars 0 forks source link

Boolean serializer incompatible with JavaScript eval #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
Duplicate of Issue 18

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

GoogleCodeExporter commented 9 years ago

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