【问题标题】:JIL json serializer does not serialize properties from derived classJIL json 序列化程序不会序列化派生类的属性
【发布时间】:2019-05-10 12:37:18
【问题描述】:

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

下面是sn-p的代码:

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

如果您有任何解决方案,请提出建议。

【问题讨论】:

    标签: c# serialization jsonserializer json-serialization jil


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 2014-03-31
      • 1970-01-01
      • 1970-01-01
      • 2012-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多