I need to extend default serialization of any object (that implements a specific interface) with, let's say for simplicity, additional properties in the generated JSON (and then be able to load this correctly).
My problem is that I've got TypeNameHandling set to Auto and if I create my custom JsonConverter (Newtonsoft.Json) and even invoke the original serialization (with the original supplied serializer by disabling my one for that time to avoid a loop) I am not getting the "$type" property generated automatically (which is required for proper deserialization). It's not automatically added by my parent and I cannot force the serializer to do it (reason below).
I am also not able to generate it myself, because I don't have any access to my context, i.e. the Type of the property that contains the object instance that I'm serializing, which states the expected type (to be compared with the actual one, to decide whether the $type should be generated or not). I can only generate it always. Is there any way to resolve this?
I want to avoid replacing the default serialization (only to extend it) and to keep the Auto
TypeNameHandling
behavior.