serializationcompositemixinscop

Serializing Composed Objects


I see Composite Oriented Programming and DCI as interesting techniques to use within a rest framework, but have run into an issue. Is it possible to serialize a mixin object and get all it's properties? For example:

public class IHasOwner 
{ 
  string owner(); 
} 

public class HasEngine 
{ 
  string engine(); 
}

Let's say we make a CarComposite object with the two classes above as mixins. Could I deserialize this CarComposite class to get the following xml?:

<CarComposite> 
   <owner></owner> 
   <engine></engine> 
</CarComposite> 

I'm curious to how this is handled in general, but with close attention to .NET, since you canot deserialize Interfaces.


Solution

  • I find that a view- or resource-model is often called for in RESTful services. I.e. a set of dumb data types tailored for the way you want to expose the resource. These do not need to match domain objects. You do need to be able map between the two though. The dumb resource-model is "easy" to serialize.

    For the mapping between domain and service model objects AutoMapper can be quite useful.