I have defined a custom Json Convertor for my DTO as below
public class CustomJsonConverter<T> : JsonConverter<T> where T : class
{
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
some code...
}
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
some code...
}
}
Then i am using it on my DTO as below
[JsonConverter(typeof(CustomJsonConverter<StudentDTO>))]
public class StudentDTO
{
some code...
}
Its all working super fine. Now All I want is At some place I want .net to use My JsonConverter and in other places i want .net to use default JsonConverter. How Do I Do it
Is there a way where I remove the converter annotation from the DTO and instead Use "JsonSerialzer.Serialize()" and somehow I can tell it which converter to use.