Limit the model data fields serialized by Web API based on the return type Interface

Posted by Stevo3000 on Stack Overflow See other posts from Stack Overflow or by Stevo3000
Published on 2012-11-27T10:52:20Z Indexed on 2012/11/27 11:04 UTC
Read the original article Hit count: 270

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about mvvm