Search code examples
c#servicestackservicestack-text

ServiceStack.Text version 5.4.0 default char value serialization and deserialization


This happends JsonSerializer but not with TypeSerializer.

Default char serialization is "\u0000" but deserialization of that string into char is '\'.

Is this a bug? or I am missing something?

Any workaraound? maybe some JsConfig.SerializeFn and JsConfig.DeSerializeFn?

I have done a simple program to test it:

public class MyObj
{
    public char AChar { get; set; }
}

public static void Main(string[] args)
{
    var obj = new MyObj();
    var json = obj.ToJson();
    System.Console.WriteLine(json);

    var newObj = json.FromJson<MyObj>();

    if (newObj.AChar == obj.AChar)
        System.Console.WriteLine("Ok!");
    else
        System.Console.WriteLine(newObj.ToJson());

}

Thanks!


Solution

  • This issue should now be resolved from this commit.

    This change is available from v5.4.1 that's now available on MyGet.