Response DTOS doesnt show properties with null value

Hi,

i have some DTOS where i want to show them even if they dont have a value set (null).
I have tried to read me trough how to fix this but can’t find how to do that.

Thx!

You can enable serializing null values globally by adding

JsConfig.IncludeNullValues = true

into Configure method or enabe serialization of null values for particular Dto by implementing RawSerializeFn and RawDeserializeFn:

JsConfig<Dto>.RawSerializeFn = (obj) =>
{
    using (JsConfig.With(includeNullValues: true))
    {
        return obj.ToJson();
    }
};

JsConfig<Dto>.RawDeserializeFn = (json) =>
{
    using (JsConfig.With(includeNullValues: true))
    {
        return JsonSerializer.DeserializeFromString<Dto>(json);
    }
};
1 Like