I have a FilterDto
class I use to send filter information to my client application.
For instance:
public class FilterDto
{
public string Code { get; set; } = "Default code";
public string Description { get; set; }
}
This is serialized like:
[
{
field: 'Code',
type: 'text',
defaultValue: 'Default code'
},
{
field: 'Description ',
type: 'text',
defaultValue: null
}
]
So in my client I can render two input
text
for the given fields. And when the user filters the JSON sent back is something like:
{
Code: 'code to filter',
Description: 'description to filter'
}
And I desserialize it like:
var filter = JsonConvert.DeserializeObject(json, typeof(FilterDto));
Console.WriteLine(filter.Code); // code to filter
The problem is, if the user decides to erase the default value for code, in the above example, I will have the JSON:
{
Description: 'description to filter'
}
And when desserializing I will have:
var filter = JsonConvert.DeserializeObject(json, typeof(FilterDto));
Console.WriteLine(filter.Code); // Default code
Is there a way to set the Code
to null instead of its default value when it is missing from the JSON?
Thanks