/// <summary> /// Configures the input and output formatters. /// </summary> /// <param name="outputFormatters">A collection of output formatters.</param> private static void ConfigureFormatters(MvcOptions mvcOptions) { // Configures the JSON output formatter to use camel case property names like 'propertyName' instead of // pascal case 'PropertyName' as this is the more common JavaScript/JSON style. JsonOutputFormatter jsonOutputFormatter = mvcOptions.OutputFormatters .OfType<JsonOutputFormatter>() .First(); jsonOutputFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // Adds the BSON input and output formatters mvcOptions.AddBsonSerializerFormatter(); // Configures the BSON output formatter to use camel case property names like 'propertyName' instead of // pascal case 'PropertyName' as this is the more common JavaScript/JSON/BSON style. BsonOutputFormatter bsonOutputFormatter = mvcOptions.OutputFormatters .OfType<BsonOutputFormatter>() .First(); bsonOutputFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // Adds the XML input and output formatter. mvcOptions.AddXmlDataContractSerializerFormatter(); // Force 204 No Content response, when returning null values. // Note that we are inserting this at the top of the formatters collection so we can select a formatter // quickly in this case. mvcOptions.OutputFormatters.Insert(0, new HttpNoContentOutputFormatter()); // Force 406 Not Acceptable responses if the media type is not supported, instead of returning the default. // Note that we are inserting this near the top of the formatters collection so we can select a formatter // quickly in this case. mvcOptions.OutputFormatters.Insert(1, new HttpNotAcceptableOutputFormatter()); }
/// <summary> /// Configures the JSON output formatter to use camel case property names like 'propertyName' instead of pascal /// case 'PropertyName' as this is the more common JavaScript/JSON style. Also adds the XML input and output /// formatters. See: http://www.strathweb.com/2015/04/asp-net-mvc-6-formatters-xml-browser-requests/. /// </summary> /// <param name="outputFormatters">A collection of output formatters.</param> private static void ConfigureFormatters(MvcOptions mvcOptions) { JsonOutputFormatter jsonOutputFormatter = mvcOptions.OutputFormatters .OfType<JsonOutputFormatter>() .First(); jsonOutputFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); mvcOptions.AddXmlDataContractSerializerFormatter(); }
/// <summary> /// Configures the input and output formatters. /// </summary> /// <param name="outputFormatters">A collection of output formatters.</param> private static void ConfigureFormatters(MvcOptions mvcOptions) { // Configures the JSON output formatter to use camel case property names like 'propertyName' instead of // pascal case 'PropertyName' as this is the more common JavaScript/JSON style. JsonOutputFormatter jsonOutputFormatter = mvcOptions.OutputFormatters .OfType<JsonOutputFormatter>() .First(); jsonOutputFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // Adds the XML input and output formatter. mvcOptions.AddXmlDataContractSerializerFormatter(); }
/// <summary> /// Configures the input and output formatters. /// </summary> /// <param name="outputFormatters">A collection of output formatters.</param> private static void ConfigureFormatters(MvcOptions mvcOptions) { // Configures the JSON output formatter to use camel case property names like 'propertyName' instead of // pascal case 'PropertyName' as this is the more common JavaScript/JSON style. JsonOutputFormatter jsonOutputFormatter = mvcOptions.OutputFormatters .OfType<JsonOutputFormatter>() .First(); jsonOutputFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // Add the XML input and output formatters. // See: http://www.strathweb.com/2015/04/asp-net-mvc-6-formatters-xml-browser-requests/. mvcOptions.AddXmlDataContractSerializerFormatter(); // TODO: Add the BSON input and output formatters. // Force 204 No Content response, when returning null values. mvcOptions.OutputFormatters.Insert(0, new HttpNoContentOutputFormatter()); // Force 406 Not Acceptable responses if the media type is not supported, instead of returning the default. mvcOptions.OutputFormatters.Insert(0, new HttpNotAcceptableOutputFormatter()); }