Serialization DateTime.MinValue

Is there something builtin (JsConfig?) to enforce that any DateTime in any DTO that has a value of DateTime.MinValue is not serialized? rather than serilizing it to 0001-01-01T00:00:00.0000000Z ?

We already use this:

JsConfig.DateHandler = DateHandler.ISO8601;

can we extend this somehow, without losing what it already does?

You can exclude default values from being serialized with:

JsConfig.ExcludeDefaultValues = true;

It’s a global option that’s not customizable to specific types but you can scope it to only apply to adhoc JSON services.

Thanks Mythz,

OK, I am worried about applying JsConfig.ExcludeDefaultValues = true;

It solves my issues with DateTime but may introduce issues with integers/longs/doubles etc. since they wont even appear in the JSON. Which may or may not break existing JS clients that do no type checking on these values. They just display them.

Is another option to simply take over the serialization/deserialization of DateTime?
If so, how to reproduce what JsConfig.DateHandler = DateHandler.ISO8601; and JsConfig.AssumeUtc = true does BUT NOT serialize DateTime.MinValue?

You can take over serialization/deserialization of DateTime using JsConfig<T> with:

Cool thanks.
Do you know any handy references for teh deserilization part of that?

If you don’t want to use the existing impl you can use: