JIL json 序列化程序不序列化来自派生 class 的属性
JIL json serializer does not serialize properties from derived class
JIL json 序列化程序不序列化派生的属性 class
下面是代码片段:
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 序列化器消除了这个 属性。
有解决办法请指教
您还必须告诉 Jil 包括继承的属性:
Jil.JSON.Serialize(context.Object, writer, Jil.Options.IncludeInherited);
JIL json 序列化程序不序列化派生的属性 class
下面是代码片段:
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 序列化器消除了这个 属性。
有解决办法请指教
您还必须告诉 Jil 包括继承的属性:
Jil.JSON.Serialize(context.Object, writer, Jil.Options.IncludeInherited);