Ignoring property in a class for response resource - Openrasta
I'm using Openrasta framework. I've simple POCO which is used in my API and this will be sent as ResponseResource to client. It looks like below:
Public class User
{
Public int Id { get; set; }
Public string Name { get; set; }
Public string Cod开发者_如何学Ce { get; set; }
}
When sending response to user I dont want to send property "Id" back to the user. How can I make openrasta serialzers to ignore this property? I tried putting XmlIgnore attribute for this property but it didn't work.
Any ideas?
Since [XmlIgnore]
isn't working, I am guessing you are using either the Json or XmlDataContract codecs. These are based on DataContractSerializer
, in which case the mechanism to control the serialization is to mark the type as [DataContract]
, at which point inclusion becomes opt in rather than automatic, i.e.
[DataContract]
public class User
{
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Code { get; set; }
}
精彩评论