after asking this question I tried to grab all this stuff for serialization in web api 2 and I read this http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml -serialization
But now I'm embarrassed
1 In my webapiconfig I do not have these lines
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter; json.UseDataContractJsonSerializer = true;
So, I assume that I am using the Json.net serializer, which is the default. Anyway, I can still use the DataContract in the class, and therefore only properties decorated with the DataMember attribute will be serialized. Are these two assumptions correct?
2 If I do not decorate the DataContract class, all properties will be serialized. This happens with both Json.net and DataContractJsonSerializer
3 If I changed (as in the question I linked), then the converter that uses it still uses it because this one or one of Json.net is not related to the other? because if i use this in global
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter; json.UseDataContractJsonSerializer = true; json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
even if it does not cause any problems, it does not seem to pick it up (and does not use its own contract resource)
3 In case I have a class that comes from another, and I decorate the parent DataContract, it seems to me that I should decorate the child properties of DataMember to serialize it. Or am I doing something wrong?
thanks
c # serialization asp.net-web-api
mitomed
source share