after asking this question I was trying to get the grips of all of this serialization stuff 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 confused
1 In my webapiconfig I don't have this lines
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.UseDataContractJsonSerializer = true;
So I asume I'm using the Json.net serializer which is the defaulted one. Anyway I still can use the DataContract in a class and therefore only the properties decorated with DataMember attribute will be serialized. Are these two assumptions correct?
2 If I don't decorate a class with DataContract all of the properties will be serialized. This happen to both the Json.net and the DataContractJsonSerializer
3 If I change (as in the question I linked) the resolver the serializer still uses it, is it because it's the Json.net one or one thing is not related to another? because if I use this in the Global
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.UseDataContractJsonSerializer = true;
json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
even if it doesn't raise any issue it doesn't seem to pick it up (nor using a custom contractresolver)
3 In case I have a class that derives from another one and I decorate the parent one with DataContract it seems to me that I have to decorate the child one's properties with DataMember for serializing it. Or am I doing something wrong?
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…