Last active
August 16, 2021 16:54
-
-
Save mauricedb/5356933 to your computer and use it in GitHub Desktop.
Return JSON data in a camelCase format from an ASP.NET WebAPI controller.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class WebApiConfig | |
{ | |
public static void Register(HttpConfiguration config) | |
{ | |
config.Routes.MapHttpRoute( | |
name: "DefaultApi", | |
routeTemplate: "api/{controller}/{id}", | |
defaults: new { id = RouteParameter.Optional } | |
); | |
// Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type. | |
// To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries. | |
// For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712. | |
//config.EnableQuerySupport(); | |
var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First(); | |
jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment