The last day I faced the problem that my ASP.NET backend was returning object properties to the client that I wanted to hide; in other words: I wanted to permit serialization of those properties. But I needed those properties to be deserialized because the client is sending them to the backend one time. That‘s why I made use of the „ShouldSerialize“-method instead of the attribute JsonIgnore. But now I noticed that those properties are also not serialized into the MongoDB where I store my objects including those properties.
How can I permit MongoDB to make use of the „ShouldSerialize“-method? Are there any other solutions to force NewtonSoft.Json to deserialize but not serialize specific properties?
I ended up using ViewModels for communication with client. The ViewModels have less properties compared to the corresponding models. Hence data annotations and other attributes can be used in the ViewModels and can be ommited in the underlying Models. Even though this architecture requires transforming Models to ViewModels and vice verca, this seems to be the common procedure.