Last active
March 23, 2022 09:51
-
-
Save robzhu/804171e2b90cc2a2958f to your computer and use it in GitHub Desktop.
OWIN Startup configuration for JSON serialization
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
using System.Collections.Generic; | |
using System.Web.Http; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Converters; | |
using Newtonsoft.Json.Serialization; | |
using Owin; | |
using Swashbuckle.Application; | |
namespace Project | |
{ | |
public class Startup | |
{ | |
public void Configuration( IAppBuilder app ) | |
{ | |
var config = new HttpConfiguration(); | |
var defaultSettings = new JsonSerializerSettings | |
{ | |
Formatting = Formatting.Indented, | |
ContractResolver = new CamelCasePropertyNamesContractResolver(), | |
Converters = new List<JsonConverter> | |
{ | |
new StringEnumConverter{ CamelCaseText = true }, | |
} | |
}; | |
JsonConvert.DefaultSettings = () => { return defaultSettings; }; | |
config.Formatters.Clear(); | |
config.Formatters.Add( new JsonMediaTypeFormatter() ); | |
config.Formatters.JsonFormatter.SerializerSettings = defaultSettings; | |
config.Routes.MapHttpRoute( "api", "{controller}/{id}", defaults: new { controller = "Root", id = RouteParameter.Optional } ); | |
config.MapHttpAttributeRoutes(); | |
config.EnableSwagger( c => | |
{ | |
c.IncludeXmlComments( "docs.xml" ); | |
c.SingleApiVersion( "1.0", "Http Request Debugger" ); | |
} ).EnableSwaggerUi(); | |
app.UseWebApi( config ); | |
} | |
} | |
} |
This does not seem to work for middleware though.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for this