简体   繁体   English

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

[英]JIL json serializer does not serialize properties from derived class

JIL json serializer does not serialize properties from derived class JIL json序列化程序不会序列化派生类的属性

Below are the code snippet: 下面是代码片段:

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) Model Type: 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; }           
}

Here when i set something to BaseBOResponse's response property "pk", then JIL serializer eliminate this property. 在这里,当我将某些内容设置为BaseBOResponse的响应属性“ pk”时,JIL序列化程序将消除此属性。

Please suggest if you have any solution. 请提出您是否有解决方案。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 json.net 不会序列化派生类的属性 - json.net does not serialize properties from derived class Jil序列化器忽略null属性 - Jil serializer ignore null properties 定制Json Serializer,通过忽略类属性来序列化和反序列化所有属性 - Custom Json Serializer to serialize and deserialize all properties by ignoring the class attributes 隐藏在派生类中后如何在json新属性中序列化 - How to Serialize in json new properties after hide it in derived class 如何在Json.Net中的派生类中仅序列化非空属性 - How to serialize only not null properties in derived class in Json.Net 从BindingList派生的类的公共字段/属性 <T> 不会序列化 - Public fields/properties of a class derived from BindingList<T> wont serialize 如何 JSON 序列化 class 派生自 Web 控制 ZA2F2ED4F8EBC2CBB4C21A29DC40AB6D1 - How to JSON serialize class derived from Web Control class 尝试使用JIL将对象序列化为Json时忽略属性被序列化(如newtonsoft中的[JsonIgnore]) - Ignore a property from being serialized when trying to serialize an object to Json using JIL (like [JsonIgnore] in newtonsoft) 序列化从不可序列化的类派生的类 - Serialize a class that is derived from a non serializable class 基本 Class 序列化问题 - 不序列化派生 Class 属性 - Base Class Serialization Issue - do not serialize Derived Class Properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM