Avoid using the JsonIgnore attribute in a domain model

后端 未结 3 1800
醉梦人生
醉梦人生 2020-12-17 18:35

I have a domain model component with several entity classes. In another component i have entity repositories implemented using Json.NET serialization. I want to ignore some

3条回答
  •  被撕碎了的回忆
    2020-12-17 19:04

    The Json serializer also supports opt-in serialization

    [JsonObject(MemberSerialization.OptIn)]
    public class File
    {
      // excluded from serialization
      // does not have JsonPropertyAttribute
      public Guid Id { get; set; }
    
      [JsonProperty]
      public string Name { get; set; }
    
      [JsonProperty]
      public int Size { get; set; }
    }
    

提交回复
热议问题