首页 文章

JIL json序列化程序不会从派生类序列化属性

提问于
浏览
0

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序列化器消除了这个属性 .

如果您有任何解决方案,请建议 .

1 回答

  • 1

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

    Jil.JSON.Serialize(context.Object, writer, Jil.Options.IncludeInherited);
    

相关问题