Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between DataMember and JsonProperty in webapi2

What is the difference between DataMember and JsonProperty when using it in webapi2? Any performance differences? What is preferred to use?

Thanks! Andreas

like image 738
ainteger Avatar asked Dec 14 '13 00:12

ainteger


1 Answers

In WebAPI, the default JSON formatter is Json.NET.

Json.NET is the one who reads the DataMember and JsonProperty attributes. JsonProperty is from Json.NET and its purpose is to control how the field or property is serialized. While DataMember, which is from Microsoft, is read by Json.NET for convenience.

JsonProperty provides more configuration options than DataMember.

like image 101
LostInComputer Avatar answered Sep 20 '22 14:09

LostInComputer