0

How to setup JsonSerializer to ignore DateTime properties with default value 0001-01-01T00:00:00, but to serialize enums and numbers with default values at the same time?

this ignores also enums:

_jsonSerializer = new JsonSerializer();
_jsonSerializer.DefaultValueHandling = DefaultValueHandling.Ignore;

and this includes also default datetimes:

_jsonSerializer.DefaultValueHandling = DefaultValueHandling.Include;
Liero
  • 22,266
  • 22
  • 120
  • 244

1 Answers1

0

I guess this is similar question and is answered: Exclude property from serialization via custom attribute (json.net)

It refers to Conditional Property Serialization article in json.net docs

_jsonSerializer.DefaultValueHandling = DefaultValueHandling.Include;
_jsonSerializer.ContractResolver = new MyShouldSerializeContractResolver();
Community
  • 1
  • 1
Liero
  • 22,266
  • 22
  • 120
  • 244