0

I'm creating a web api 2 application and I have been using the XMLSerializer to serialize my objects. However, due to legacy objects I added after that, everything I did using the serializer is coming in null.

I think my only choice is to use DataContracts however is there a way to add a default namespace and not have to add [DataContract] and [DataMember] to all the objects in my api?

Here is a simplified example of an object

public class Color
{   
public int ID { get; set; }
public Guid? SiteID { get; set; }
public int? Rank { get; set; }
public string Name { get; set; }
public string Code { get; set; }
}
Kurohoshi
  • 103
  • 3
  • 12
  • http://stackoverflow.com/questions/771560/how-do-you-configure-wcf-known-types-programmatically – Marcel N. Aug 07 '14 at 17:18
  • You can mark only the class as serializable, then every member will be serializable as well. – Fals Aug 07 '14 at 17:18
  • See my link, you can put all your types in a function and return them to be used by attribute `ServiceKnownType`. It doesn't get any easier/centralized than that. – Marcel N. Aug 07 '14 at 17:19
  • @MarcelN. I should have mentioned and edited my post for it, but I'm making an API. Don't know if that changes things but I'm still trying to understand the KnownType things, but it seems like I will still need to decorate my classes with that. So would there be a real advantage to that over just sucking it up and decorating my classes/members with the DataContract stuff? Thanks! – Kurohoshi Aug 07 '14 at 18:07
  • @Fals I tried that but I still get a null object. – Kurohoshi Aug 07 '14 at 18:08
  • @Kurohoshi: The advantage is visible when you have many (many) data contracts (tens or hundreds). It is useful to group them like that because if anything changes in this regard you want to modify 1 file only, not who knows how many. – Marcel N. Aug 07 '14 at 18:43

0 Answers0