I'm struggling with custom json serialization in .Net core, I'm trying to make all properties required by default except if property has specific type. Here is an example of what I'm trying to achieve:
Let's assument that I have following type: F#:
type FooType = {
id: int
name: string
optional: int option
}
you can think about below code as similar to following in C#:
class FooType =
{
int Id {get;set;};
string Name {get;set;};
Nullable<int> Optional {get;set;};
}
What I'm trying to do is to return error if Id or Name property is missing in json object but deserialize without error if Optional is missing (so basically to set Property as required or not based on it's type). I'm able to mark all properties as required by using RequireObjectPropertiesContractResolver
from this sample: https://stackoverflow.com/a/29660550 but unfortunately I wasn't able to build something more dynamic.
I have also default converter for Optional types I would like to add to serialization. It's not part of this one specific question but if you have an idea how to mark property to be required or not and to use custom Converter in one place than it would be even greater.