This is probably very simple to do however i haven't been able to get it working.
I have the following RAML contract
types:
EpaymentItem:
type: object
properties:
Payment: string
EpaymentTypeTwo:
type: EpaymentItem
properties:
Card: string
EpaymentTypeThree:
type: EpaymentItem
properties:
Bill: string
EpaymentDTO:
type: object
properties:
payment: EpaymentItem
name: string
address: string
/Epayment:
/{paymentId}
get:
responses:
200:
body:
application/json:
type: EpaymentDTO
Now the thing i cant get to work is that whenever I'm trying to reply with either EpaymentTypeTwo or EpaymentTypeThree the json deserializer thinks its just an EpaymentItem. Unless i specify the type as the one it will be getting back it always deserializes into the baseclass.
Is there a way to make the deserializer understand that the type arriving at im is an inherited class?.
Thanks in advance!
EDIT1: Added deserializer. The serializer cant be shows since its done through a IHttpActionResult.
if (typedContent != null)
return typedContent;
IEnumerable<string> values = new List<string>();
if (RawContent != null && RawContent.Headers != null)
RawContent.Headers.TryGetValues("Content-Type", out values);
if (values.Any(hv => hv.ToLowerInvariant().Contains("xml")) &&
!values.Any(hv => hv.ToLowerInvariant().Contains("json")))
{
var task = RawContent.ReadAsStreamAsync();
var xmlStream = task.GetAwaiter().GetResult();
typedContent = (EpaymentDTO)new XmlSerializer(typeof(EpaymentDTO)).Deserialize(xmlStream);
}
else
{
var task = Formatters != null && Formatters.Any()
? RawContent.ReadAsAsync<EpaymentDTO>(Formatters).ConfigureAwait(false)
: RawContent.ReadAsAsync<EpaymentDTO>().ConfigureAwait(false);
typedContent = task.GetAwaiter().GetResult();
}
return typedContent;