ServiceStack.Text: JSON serialization issue with custom serialization of long

26 Views Asked by At

When using a custom serialization for long:

JsConfig<long>.SerializeFn = value => value.ToString();

And then attempting to serialize a dictionary:

Dictionary<long, string> dict = new Dictionary<long, string> 
{
    { 1, "One" },
    { 2, "Two" }
};

Console.WriteLine(dict.ToJson());

Ends up with the output:

{""1"":"One",""2"":"Two"}

Which is not valid JSON.

This isn't the end of the world, the custom serialization works everywhere the long doesn't end up as a key in the JSON.

This means that the data can serialized as a list and converted to a dictionary/map on the other end.

The latest version of ServiceStack.Text (NuGet feed, did not look at the pre-release feed) still exhibits this behavior.

Is this outside the scope of the serializer provided by ServiceStack.Text, is this a bug or does anyone have any work arounds?

If this is outside of scope or not easy to fix I'll just go with using lists in the DTOs instead of dictionaries.

0

There are 0 best solutions below