JsConfig for TypeSerializer

According to the documentation: “The JSON/JSV and CSV serialization can be customized globally by configuring the JsConfig or type-specific JsConfig static classes with your preferred defaults.” changing JsConfig should impact TypeSerializer behavior also, but it seems that setting IncludeNullValues / IncludeNullValuesInDictionaries does not change the resulting Jsv.

My example:

static void Main(string[] args)
{
var dict = new Dictionary<string, string>
{
{ “key1”, “value1” },
{ “key2”, null }
};

Console.WriteLine($"Jsv without config : {TypeSerializer.SerializeToString(dict)}");
Console.WriteLine($"Json without config : {JsonSerializer.SerializeToString(dict)}");

using (JsConfig.With(new Config
       {
           IncludeNullValues = true,  // not really needed
           IncludeNullValuesInDictionaries = true
       }))
{
    Console.WriteLine($"Jsv with config : {TypeSerializer.SerializeToString(dict)}");
    Console.WriteLine($"Json with config : {JsonSerializer.SerializeToString(dict)}");
}

}

produces jsv without the key-value where value = null, while json has the entry:

Jsv without config : {key1:value1}
Json without config : {“key1”:“value1”}
Jsv with config : {key1:value1}
Json with config : {“key1”:“value1”,“key2”:null}

Am I missing something here or is this normal behavior for jsv serialization?

Many thanks for your answer, best regards!

JSV can’t serialize null which it can’t distinguish from the “null” literal string so it always excludes null values which prevents populating nullable properties, leaving them at their default null value.

If you need explicit null values you’ll need to use JSON.

Got it. Many thanks for your quick reply!