There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Add support to add $type only for particular types
I was looking for a way to add type information to serialized object tree, but only to objects of particular types, which will be treated specially on a client side. I don't want to add $type to every object, because it will significantly increase json
I was expecting that it would be possible to achieve by decorating the default IContractResolver and setting some special property indicating that $type property is required. Turned out that a contract cannot tell that a $type property must be added, it can
only tell that such property should be added to serialized values of its properties. Since JsonSerializerInternalWriter is ..hm.. internal, I cannot modify the decision making process on whether or not $type property should be written.
Of course, one can always implement a custom JsonConverter for types he\she wants, and write $type property to the result manually, but that's somewhat hacky since (a) '$type' string is not exposed as public, (b) it seems almost impossible to just add a property
for a type without overriding whole serialization of that type.
So, could please add a support that would make this scenario possible?