Pending Review
Last Updated: 27 Mar 2015 14:05 by ADMIN
Imported User
Created on: 16 Sep 2013 13:01
Category: UI for ASP.NET MVC
Type: Feature Request
Allow for replacing the JavascriptSerializer used by the Grid
We all know that the default JavascriptSerializer built into ASP.NET leaves much to be desired, which is why developers are swapping out the built in one from ASP.NET for others such as JSON.NET and ServiceStack.

The issue that a lot of developers encounter when working with the MVC Wrappers is that it appears to be using the build in JavascriptSerializer, which is miserably slow and hard to work with when trying to take data from an ORM (with navigation properties) and display it on the Grid. Most of our grids closely represent a table in our database, but because the JavascriptSerializer doesn't support any type of navigation properties, we are always forced to write some DTO that flattens the object out to contain just simple datatype properties.

If we could REPLACE the JavascriptSerializer with our own framework - such as JSON.NET or ServiceStack, then we would be able to get our job done a lot faster without the extra plumbing.

This feature would mean that this "known issue" could be resolved by people simply swapping the JavascriptSerializer for a better one:
1 comment
Posted on: 18 Dec 2013 21:46
Hi Adam,

This can actually be achieved quite easily:
1. Implement IJavaScriptSerializer, e.g. MyCustomJavaScriptSerializer : IJavaScriptSerializer.
You only need to implement the Serialize() method, e.g. return JsonConvert.SerializeObject(value) or use the overload that takes settings JsonConvert.SerializeObject(value, serializerSettings)
2. Create a specialized JavaScriptInitializer, .e.g, MyCustomJavaScriptInitializer : JavaScriptInitializer and override the CreateSerializer method where you return  a new instance of your implementation of IJavaScriptSerializer, e.g. return new MyCustomJavaScriptSerializer()
3. In App_Start you can register your own JavaScriptInitializer:
Kendo.Mvc.Infrastructure.DI.Current.Register<IJavaScriptInitializer>(() => new MyCustomJavaScriptInitializer());
VoliĆ” :)

Best regards
Jakob Engelbrecht