I'm trying to add a custom xml deserializer to the ASP.Net Core pipeline for one of my controllers. I've been able to do it for JSON like this:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.Configure<MvcOptions>(options =>
{
options.RespectBrowserAcceptHeader = true;
// Input formatters
var xmlInputFormatting = new XmlDataContractSerializerInputFormatter();
var jsonInputFormatting = new JsonInputFormatter();
jsonInputFormatting.SerializerSettings.Converters.Add(new BatchContentConverter());
options.InputFormatters.Clear();
options.InputFormatters.Add(jsonInputFormatting);
options.InputFormatters.Add(xmlInputFormatting);
}
}
(a lot unnecessary code has been removed for brevity).
The controller action where this should end up is:
public IActionResult Post([FromBody]IBatchContent batchContent)
{
}
Is there any way to do something similar for XML using either the XMLSerializerInputFormatter or the XmlDataContractSerializerInputFormatter? I've tried creating a class descended from DataContractResolver and assigning it to the SerializerSettings.DataContractResolver property but it never seems to get called.