2

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 序列化程序会消除此属性。

请建议您是否有任何解决方案。

4

1 回答 1

3

您必须告诉 Jil 也包括继承的属性:

Jil.JSON.Serialize(context.Object, writer, Jil.Options.IncludeInherited);
于 2018-12-09T22:14:01.373 回答