I have a lot of objects (type A) that contain a field which is a very large object itself (type B).
When I serialize objects of type A, I don't want to include the contents of B but I want to replace that field by a string.
I understand I can make a custom serializer but the serialization is done through an object that is passed to me (based on json.net), so I can't initialize my own serializer at that level in the call hierarchy and the type in question is not known where the serializer is initialized.
I saw that you can make serialization conditional by including a method in the object itself ("ShouldSerialize<fieldname> : bool) and I was wondering if there is a similar mechanism to serialize a specific type with a custom serializer where I'd embed the serializer in the object definition.
[JsonIgnore]on the object property.[JsonIgnore]see Unwrapped property in C# JSON. ForJsonConverteron a property that serializes an object as a string, see custom serializer for just one property in Json.NET + Json.Net: Serialize/Deserialize property as a value, not as an object.