The class that I need gets serialized as a web service response body.
The problem is, the properties from the base class get serialized along with it, and I can't have that for this service.
I need to block those properties from being serialized on only this subclass. So I tried hiding the properties using new
but the base class properties are still being serialized (i.e. "Hello, world" is in the resulting http response body):
public class MyBaseClass
{
public string MyProperty { get { return "Hello, world"; } }
}
public class MyChildClass : MyBaseClass
{
[XmlIgnore]
[JsonIgnore]
public new string MyProperty { get; set; }
}
this gets returned via something like this:
return myHttpRequestMessage.CreateResponse(myStatusCode, myChildClassInstance);
So two questions
- What up with that? Why isn't it honoring the child class with its decorations?
- Is there another way to achieve what I'm trying to achieve (which is preventing the decorated properties from being serialized?
I know it's a total kludge, but until I have the time to fix the deeper issue (which is the operation that's forcing this inheritance), this is what I have to work with.