We use JSON.net and want to use a consistent way of sending and receiving data (documents).
We want the base class to receive all documents. The base class will have the DocumentType property - this is, in fact, the name of the class.
When clients send this serialized json document to the server, we want to deserialize it and make sure that the specified DocumentType specified by the client matches the ExpectedDocumentType on the server.
Then, like this, when this document is serialized by the server and sent to the client, we want the DocumentType property to be included in the JSON. The trick is that we want this value to be the same as in ExpectedDocumentType.
I tried to do it like this ... This will work if the JsonProperty and JsonIgnore attributes only affect serialization, but not deserialization, but unfortunately this is not the case.
public abstract class JsonDocument {
Does anyone know how to achieve this?
In essence, the logic is that the client can provide any type of DocumentType, so when deserializing the server, you need to make sure that it matches the ExpectedDocumentType, and then during serialization, when the server sends this document to the client, the server knows the correct DocumentType, so it needs to be filled him using ExpectedDocumentType.
Tyler
source share