Web API–How to change Default Serializer settings

Out of box, Web API provides a way to serialize using JSON and XML.
In this blog post, I will describe how you can control JSON settings for the default serializer.

JSON Settings.

e.g Say you want your date to be formatted as per Microsoft format as opposed to ISO standard (for whatever reason).
All you do is get hold of the jsonFormatter and then use SerializerSettings to set DateFormatHandling.

JsonDateFormatCode

ISO Date Format for JSON

isoFormat

Microsoft Date Format for JSON.

microsoftdateFormat

By default, Json.NET will use ISO format for your date time format serialization

Advertisements