I am attempting to force a camelCase response with the following line in my ConfigureApp method:
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
The entire method:
public static void ConfigureApp(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.Formatters.JsonFormatter.UseDataContractJsonSerializer = false;
appBuilder.UseWebApi(config);
}
And I'm returning the following response from my controller:
public object Get()
{
var result = new { name = "alex", number = 1, lastname = "smith" };
return Ok(result);
}
The response I am getting is:
{"name":"alex","number":1,"lastname":"smith"}
The response I am expecting is:
{"name":"alex","number":1,"lastName":"smith"}
How do I force camelCase response (lastname vs lastName)?