title: ASP.NET Core API JSON serializersettings per request
body: <p>Based on some value in the request (header or in the url) I want to change the serialization of my DTO objects.
  Why? Well I've applied the <code>[JsonProperty("A")]</code> to my DTO's but depending on the client (website or mobile app) it want to use that property or not.
  I started with</p>
  
  <pre><code>services
  .AddMvc()
  .AddJsonOptions(opt =&gt;
  {
  #if DEBUG
      opt.SerializerSettings.ContractResolver = new NoJsonPropertyNameContractResolver();
  #endif
  }
  </code></pre>
  
  <p>So while debugging I get JSON with full propertynames. I use the <code>JsonProperty</code> attribute to shorten the response JSON, which works fine with the mobile app (Xamarin) which deserialize back to the same DTO's.
  But now I have a website which uses the the same API to get data via jQuery, but in there I want to deal with the full property names of the DTO's, not the name given in the <code>JsonProperty</code> attribute.
  Website and WebApi are on the same server so it's no problem if the response is a little bigger.</p>
  
  <p>I started with a middleware class to react on a customer header value, which works, but now I don't know how to get to the JSON SerializerSettings. Searched the web but cannot find it.</p>
  
  <p>While searching I've read about InputFormatters and OutputFormatters, and also content negotiation, but I don't know which direction I must go.</p>
  
  <p>I don't want to deploy the same API twice with different settings.<br>
  I'am able to change things like the routesconfig if that would help.</p>
  
  <p><strong>Update</strong><br>
  Not only the JSON response had to be serialized in 2 different ways, also the deserializing had to be done in 2 different ways. </p>