I currently have my web API set up to return all JSON in a camelCase format with the following code in WebApiConfig
:
var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
formatter.SerializerSettings.ContractResolver =
new
Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
And it works wonderfully. However, I am using the jQuery Datatable plugin and am saving/loading the state through my API, and it requires the data to be returned in a TitleCase format. Now obviously I'm not going to rewrite my entire consuming application(s) to except TitleCase formated Json, so I need my LoadState
route only to return TitleCase format.
I've tried things such as:
[HttpGet]
[Route("api/Controller/LoadState")]
public IHttpActionResult LoadState()
{
var state = _eService.LoadState(UserProfile.IndividualId);
//requires title cased object
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.ContractResolver = new DefaultContractResolver();
return Ok(state);
}
But this seems to set the entire application to TitleCase and overwrite my settings in the WebApiConfig
. Anyone have any recommendations?