-
Notifications
You must be signed in to change notification settings - Fork 11
JSON serialization customization
gimmi edited this page Dec 6, 2011
·
1 revision
By using Json.NET, DirectHandlerInterceptor allow great flexibility on JSON serialization. To customize how Json.NET serialize/deserialize method parameters you can procede as follows:
public class Global : HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
...
DirectHttpHandler.SetDirectHandlerInterceptor(delegate(Type type, MethodInfo method, DirectHandlerInvoker invoker) {
var jsonSerializer = new JsonSerializer {
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
jsonSerializer.Converters.Add(new MyCustomJsonConverter()); // Example of custom JSON converter
invoker.Invoke(jsonSerializer: jsonSerializer);
});
...
}
}