35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
|
|
namespace FormatterWebSite
|
|
{
|
|
/// <summary>
|
|
/// Summary description for DataContractSerializerController
|
|
/// </summary>
|
|
public class DataContractSerializerController : Controller
|
|
{
|
|
public override void OnActionExecuted(ActionExecutedContext context)
|
|
{
|
|
var result = context.Result as ObjectResult;
|
|
if (result != null)
|
|
{
|
|
result.Formatters.Add(new XmlSerializerOutputFormatter());
|
|
result.Formatters.Add(new XmlDataContractSerializerOutputFormatter());
|
|
}
|
|
|
|
base.OnActionExecuted(context);
|
|
}
|
|
|
|
[HttpPost]
|
|
public Person GetPerson(string name)
|
|
{
|
|
// The XmlSerializer should skip and the
|
|
// DataContractSerializer should pick up this output.
|
|
return new Person(name);
|
|
}
|
|
}
|
|
} |