NancyFx/Nancy — Issue #512: JsonSerializer doesn't like DynamicDictionaryValue
Author: DaveVdE
Created: 2012-02-20 20:41:33+00:00
State: open

Consider this trivial route handler:

Get["/{name}"] = parameters =>
{
return Response.AsJson(new {name = parameters.name});
};

This produces the unexpected result of:

{"name":Dave}

and this is because JsonSerializer does not regard the DynamicDictionaryValue to be of type String, and therefore tests if it's an IConvertible and simply writes the output of the conversion as is without treating it as a string literal.

Replacing the default JsonSerializer with ServiceStack.Text doesn't help, as it decides that it should treat it as an object and reflect all its properties, and produces this:

{"name":{"HasValue":true,"Value":"Dave"}}