Is it possible on System.Text.Json
to conditionally ignore when default if it is a certain type?
Because I have this type
public struct Optional<T>
{
public bool HasValue { get; init; }
public T Value { get; init; }
public Optional(T value) =>
(HasValue, Value) = (true, value);
}
I can ignore it when default globally with JsonSerializerOptions.DefaultIgnoreCondition
but this also means if I have a bool
with false value or int
with 0 value it will be ignored, and I only want to ignore when default if the type is specifically Optional<T>
Any suggestions?
Also, I don't want to use [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
, I know I can do that but I want to make it globally with that certain type