JSON.Net - Use JsonIgnoreAttribute only on serialization (But not when deserialzing)

后端 未结 2 1918
囚心锁ツ
囚心锁ツ 2020-12-22 00:22

We\'re using JSON.net and want to use a consistent way to send and receive data (documents).

We want a base class that all documents will be derived from. The base c

2条回答
  •  独厮守ぢ
    2020-12-22 01:10

    You can do this with an Enum, I don't know if DocumentType is a enum but it should.

    enum DocumentType {
        XML,
        JSON,
        PDF,
        DOC
    }
    

    When deserializing the request it will give you an error if the client sends you an invalid enum. The "InvalidEnumArgumentException" which you can catch and tell the client that it's sending an non valid DocumentType.

提交回复
热议问题