Shovra
Shovra

Reputation: 76

Set XML as default output format in ASP.NET Core 2.0

I have added XmlFormaterExtensions like below code which works fine with an Accept header. My query is:

  1. How do I set XML as default o/p format instead of JSON?
  2. 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!

Upvotes: 1

Views: 1240

Answers (1)

Edward
Edward

Reputation: 29986

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);
    }

Upvotes: 2

Related Questions