问题
I have added XmlFormaterExtensions like below code which works fine with an Accept header. My query is:
- How do I set XML as default o/p format instead of JSON?
- Is there any trick to set the XML for-matter to Camel Case instead of Pascal Case
I am using ASP.NET Core 2.0 (Asking for o/p format only)
public void ConfigureServices(IServiceCollection services){
services.AddMvc()
.AddXmlFormaterExtensions()
.AddJsonOptions(options => {
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});}
Thanks in advance!
回答1:
How do I set XML as default o/p format instead of JSON?
For this requirement, try code below:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options => {
options.OutputFormatters.Insert(0, new XmlDataContractSerializerOutputFormatter());
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
来源:https://stackoverflow.com/questions/54541551/set-xml-as-default-output-format-in-asp-net-core-2-0