Is there any way to selectively skip serialization of fields whose value is equal to a certain known value? AFAIK, DefaultContractResolver isn't enough to achieve this as it doesn't allow to get the field's value.
Asked
Active
Viewed 128 times
1
-
You could use the `ShouldSerializeXXX()` pattern. See e.g. [How to use `ShouldSerialize[MemberName]()` method for a property of type Object?](https://stackoverflow.com/q/19698844/3744182). Or you could use `DefaultValueHandling = DefaultValueHandling.Ignore`, see [this answer](https://stackoverflow.com/a/46767921/3744182) for a single property and [this answer](https://stackoverflow.com/a/62676615/3744182) for use in settings. Do those answer your question? If not, could you [edit] your question to provide more details, ideally a [mcve]? – dbc May 14 '21 at 02:50
-
1[This answer](https://stackoverflow.com/a/62699016/10263) shows how to do it with a custom ContractResolver. – Brian Rogers May 14 '21 at 03:13