JIL json序列化程序未序列化派生类
下面是代码段:
public async Task WriteAsync(OutputFormatterWriteContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var response = context.HttpContext.Response; response.ContentType = "application/json";
using (var writer = context.WriterFactory(response.Body, Encoding.UTF8))
{
Jil.JSON.Serialize(context.Object, writer);
await writer.FlushAsync();
}
}
1)型号:
public class BaseBOResponse
{
public string pk { get; set; }
}
public class PaymentTypeBOResponse : BaseBOResponse
{
public string description { get; set; }
public bool isSystem { get; set; }
public bool isActive { get; set; }
}
在这里,当我将某些内容设置为BaseBOResponse的响应属性“ pk”时,JIL序列化程序将消除此属性。
请提出您是否有解决方案。
答案 0 :(得分:1)
您还必须告诉Jil也包括继承的属性:
Jil.JSON.Serialize(context.Object, writer, Jil.Options.IncludeInherited);