Possible QuoteName = false issue in 5.0.7

Oct 15, 2013 at 9:13 PM
Edited Oct 16, 2013 at 5:23 PM
It appears the 5.0.7 release has introduced a change of functionality (or defect?) with how .WriteValue() values are serialized/rendered if QuoteName = false.

The following sample demonstrates how to reproduce the issue (requires 5.0.7):

Example
<%@ Page Language="C#" %>

<%@ Import Namespace="Newtonsoft.Json" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        var sb = new StringBuilder();
        var sw = new System.IO.StringWriter(sb);
        var writer = new JsonTextWriter(sw);

        // Issue in 5.0.7 release
        // if .QuoteName = false, then string value is not properly serialized with quotes.         
        writer.QuoteName = false; 
        
        writer.WriteStartObject();

        writer.WritePropertyName("name");
        writer.WriteValue("value"); // <-- not wrapped in quotes in 5.0.7. Correct functionality in 5.0.6.

        writer.WriteEndObject();
        writer.Flush();

        this.Literal1.Text = sw.GetStringBuilder().ToString();
    }
</script>

<!DOCTYPE html>
    
<html>
<head>
    <title>Json.NET Example</title>
</head>
<body>
    <asp:Literal ID="Literal1" runat="server" />
</body>
</html>
Results:
// Expected 5.0.7
writer.QuoteName = false; 
{name:"value"}

// Actual 5.0.7
writer.QuoteName = false; 
{name:value} // error, string value is not quoted

// Actual 5.0.6
writer.QuoteName = false; 
{name:"value"} // correct
In Json.NET 5.0.6 the value is serialized correctly if QuoteName = false.

Maybe we're missing something somewhere or misunderstanding the functionality of .QuoteName, although at a minimum, the functionality of QuoteName has changed from 5.0.6 to 5.0.7.

Hope this helps.
Coordinator
Oct 16, 2013 at 11:58 AM
It's a bug. It will be fixed today.
Coordinator
Oct 17, 2013 at 1:46 AM