views:

32

answers:

1

I have a number of interfaces I use to pass business objects around in my application. Using Ninject, I can do whatever I want with them without needing to know the type of the actual object; in this case, most of them are actually various Linq to Sql objects that implement the interface.

For example, I have a Linq to Sql object called Listing that implements IListing.

Where I've run into a problem is with serialization. I've tried using the built in JsonResult and JsonNet. Both of them attempt to serialize the actual Linq to Sql object, not just the properties defined in the interface type. This leads to circular reference issues, but the larger problem is that I only want the properties defined in the interface being serialized and passed around.

So, is there an elegant way to serialize just the properties defined in an instance of an interface that I pass to a serializer?

A: 

You could define a new transport type containing only the properties you need and then use AutoMapper to convert between your domain object to this type which will be used for serialization.

Darin Dimitrov