ASP.NET Web API format datetime differently between two APIs in the same Web app

Viewed 2035

I am using the normal way to configure Web APIs in my project, however, I do have a legacy API which I need to support.

I configure the datetime format like this:

JsonMediaTypeFormatter jsonFormatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
        jsonFormatter.SerializerSettings = new JsonSerializerSettings
        {
            NullValueHandling = NullValueHandling.Include,
            ContractResolver = new CamelCasePropertyNamesContractResolver()
        };
        var converters = jsonFormatter.SerializerSettings.Converters;
        converters.Add(new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-ddTHH:mm:ss" });

This is exactly what I want for most of the API controllers, however, with the legacy API, it needs to output DateTimes using the old MS AJAX format, like this:

/Date(1345302000000)/

So anyone know how I can specify a different JSON date formatter for one of my API modules and leave the Global Configuration as-is? OR any alternative, such as a config per API would be fine. thanks

1 Answers
Related