0

I would like to change the default serialization mode in Json.NET from MemberSerialization.OptOut to MemberSerialization.Fields without needing to scatter [JsonObject(MemberSerialization.Fields)] attributes through every class in my code base.

My primary reasons for wanting this is to get my Json deserializer to not call constructors and to make sure that all fields, including private ones, are correctly serialized and deserialized.

An example of the behaviour I'm looking for would be the serialization / deserialization behaviour of the BinaryFormatter, except without needing to scatter [Serializable] attributes through the entire codebase.

Allen Pestaluky
  • 3,126
  • 2
  • 20
  • 22
  • To my surprise, Json.NET seems to be respecting the attributes on parent classes through inheritance. I believe this is not the way attributes normally behave, but for me it means that I no longer need to scatter [JsonObject(MemberSerialization.Fields)] attributes everywhere because I can just put a few on the parent classes and be done with it. – Allen Pestaluky Aug 06 '20 at 21:19
  • Do the answers from [JSON.Net: Force serialization of all private fields and all fields in sub-classes](https://stackoverflow.com/q/24106986/3744182) work for you? – dbc Aug 08 '20 at 19:57

0 Answers0