Limit the model data fields serialized by Web API based on the return type Interface
- by Stevo3000
We're updating our architecture to use a single object model for desktop, web and mobile that can be used in the MVVM pattern. I would like to be able to limit the data fields that are serialized through Web API by using interfaces on the controllers. This is required because the model objects for mobile are stored in HTML5 local storage so don't carry optional data while a thin desktop client would be able to store (and work with) more data.
To achieve this a model will implement the different interfaces that define which data fields should be serialized and there will be a controller specific to the interface.
The problem is that the Web API always serializes every field in the model even if it is not part of the interface being returned. How can we only serialize fields in the returned interface?