Can I optionally turn off the JsonIgnore attribute at runtime?

后端 未结 3 882
一生所求
一生所求 2020-11-29 05:41

I am creating a JSON file with Newtonsoft.Json from a set of classes. The file created is very large, so I have created JsonProperty\'s for the properties to re

3条回答
  •  猫巷女王i
    2020-11-29 06:37

    If you are willing to use F# (or simply use an API not optimized for C#), the FSharp.JsonSkippable library contains a generic wrapper type that allows you to control in a simple and strongly typed manner whether to include a given property when serializing (and determine whether a property was included when deserializing), and moreover, to control/determine exclusion separately of nullability. (Full disclosure: I'm the author of the library.)

提交回复
热议问题