我有这个 ASP.NET Core 2.0 MVC 控制器:
[Route("api/[controller]")]
public class SampleDataController : Controller
{
[HttpGet("[action]")]
public Example Demo()
{
return new Example("test");
}
public class Example
{
public Example(string name)
{
Name = name;
}
public string Name { get; }
public IEnumerable<Example> Demos
{
get { yield return this; }
}
}
}
Run Code Online (Sandbox Code Playgroud)
查询时/api/SampleData/Demo,我得到响应正文:
{"name":"test","demos":[
Run Code Online (Sandbox Code Playgroud)
...这显然是非常破碎的类似 JSON 的输出。
我必须如何以及在哪里配置基于 ASP.Net Core 2.0 MVC 的应用程序,以使框架以不破坏输出的方式序列化循环引用?(例如,通过引入$ref和$id。)