cvent / deprecated-json-schema-2-poco

Converts JSON schemas to C# POCOs
18 stars 27 forks source link

Support attributes required for JSON.net deserialization #15

Open sbl03 opened 10 years ago

sbl03 commented 10 years ago

Currently, all the validation attributes are made for validation with ASP.NET WebAPI. They come from the System.ComponentModel.DataAnnotations namespace. To make the attributes work when deserializing with JSON.net, the attributes must be under the JsonProperty attribute.

Example: Currently, a required attribute looks like this:

[Required()]

To be deserializable with JSON.net, it must look like this:

[JsonProperty(Required = Required.Always)]

An option should be given to decide which set of attributes to use.


Relevant SO. WebAPI Validation.

lroling8350 commented 10 years ago

I don't believe this will work. The JsonProperty can't be used to wrap the DataAnnotations namespace. The JsonProperty also does not support all the validation types, it only supports required.