I need to get subset in the REST response. How I can reach that? For example, we have class:
[DataContract]
public class Response
{
[DataMember]
public string id { get; set; }
[DataMember]
public string href { get; set; }
[DataMember]
public string name { get; set; }
}
And variable bool flag
In my response I need only href
and id
fields if flag
equals true
. And if flag
equals false
, I should return all fields.
My GET method is implemented through the code:
public interface IRestServiceImpl
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "Response/{*id}?fields={fieldsParam}")]
}
This functionality is need for supporting fields
request param.
I found EmitDefaultValue
attribute for non serialization, but it works only with default values.
Should I customized serializer or data attributes?