views:

68

answers:

1

I have some types which are generated by a web service reference. I want to serialize these objects using the DataContractJsonSerializer, so I need to add DataContract and DataMember attributes. Adding DataContract is no problem using partial classes. But the properties have no DataMember attributes, so I only get empty objects. Is there a way to get this to work in case one cannot modify the serialized types?

A: 

Unlike XmlSerializer, I don't think (from memory) that there is a ctor for passing in this extra metadata at runtime. Perhaps another viable option is to have a twin DTO class that is attributed, and shuffle the data into there? You can add a conversion method / operator (between the two) in the partial class. Not ideal maybe, but it'll work.

Marc Gravell
Not the answer I was looking for, but you are probably right. I wanted to get rid of the extra classes but it looks like I have to implement them.
Achim