rpgmaker / NetJSON

Faster than Any Binary? Benchmark: http://theburningmonk.com/2014/08/json-serializers-benchmarks-updated-2/
MIT License
230 stars 29 forks source link

String deserialization fails #218

Closed jfontsaballs closed 5 years ago

jfontsaballs commented 5 years ago

Hello,

Trying to serialize an string is not working properly as the deserialized string is not equal to the previously serialized string. Please see code below.

static void Main()
{
    var netJsonSettings = new NetJSONSettings {
        CaseSensitive = true,
        DateFormat = NetJSONDateFormat.ISO,
        IncludeTypeInformation = true,
        UseEnumString = true,
        UseStringOptimization = true
    };
    var myString = "MyString";

    var serialized = NetJSON.NetJSON.Serialize(myString, netJsonSettings);
    var result = NetJSON.NetJSON.Deserialize<string>(serialized, netJsonSettings);

                                            // Console output
    Console.WriteLine(myString == result);  // False (!!! I expected this to be true)
    Console.WriteLine(serialized);          // "MyString"
    Console.WriteLine(myString);            // MyString
    Console.WriteLine(result);              // "MyString" (result string should not contain quotes, as the original string didn't)

    Console.ReadLine();
}
rpgmaker commented 5 years ago

Thanks will look into it.

rpgmaker commented 5 years ago

The issue is resolved. Please test with the branch if you can. I will make it a nuget package once i fix the other pending issues.

Thanks,

jfontsaballs commented 5 years ago

Issue seems resolved.

static void Main()
{
    var netJsonSettings = new NetJSONSettings {
        CaseSensitive = true,
        DateFormat = NetJSONDateFormat.ISO,
        IncludeTypeInformation = true,
        UseEnumString = true,
        UseStringOptimization = true
    };
    var myString = "MyString";

    var serialized = NetJSON.NetJSON.Serialize(myString, netJsonSettings);
    var result = NetJSON.NetJSON.Deserialize<string>(serialized, netJsonSettings);

                                            // Console output
    Console.WriteLine(myString == result);  // False (!!! I expected this to be true)
    Console.WriteLine(serialized);          // "MyString"
    Console.WriteLine(myString);            // MyString
    Console.WriteLine(result);              // MyString (Now we get the expected result)

    Console.ReadLine();
}

Thank you very much.