I want to serialize HttpListenerContext
instance. But there are some mutable properties in this class, that cause side effects and JsonConverter
just throw an error, when try to serialize an instance of this class.
What is the best solution for this problem? I see next ways to deal with it:
- Create custom wrapper class and list all necessary fields in it
- Write custom
ContractResolver
with tricky condition for serializable properties (for example: serialize only auto properties)
Can you suggest something? What is a general approach for this situation? How should I serialize mutable objects from external libraries?
For serialization, I use Newtonsoft.Json
library and serialize object with JsonConverter.SerializeObject(...)
method.