Use System.Text.Json source generator with custom JsonConverter
According to the documentation you can create a JsonSerializerOptions, add your converter and use it in the serialization.
var options = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
WriteIndented = false,
};
options.Converters.Add(new MyConverter());
var myJsonSerializerContext = new MyJsonSerializerContext(options);
You cant share your JsonSerializerOptions with several SerializerContext, another thing it was not clear to me reading the documentation is that you can have one SerializerContext for n types.
So you can have one SerializerContext for all your types initialize and cache it so you can reuse it to avoid allocating more memory.