c# - RAML 类型继承 C#
问题描述
这可能很简单,但是我无法让它工作。
我有以下 RAML 合同
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
现在我无法开始工作的是,每当我尝试使用 EpaymentTypeTwo 或 EpaymentTypeThree 进行回复时,json 反序列化器都会认为它只是一个 EpaymentItem。除非我将类型指定为它将返回的类型,否则它总是反序列化到基类中。
有没有办法让反序列化器明白到达 im 的类型是一个继承的类?
提前致谢!
EDIT1:添加了解串器。序列化程序无法显示,因为它是通过 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;
解决方案
推荐阅读
- angular - Angular 本地化无法运行 CLI
- swift - SwiftUI Button 文本对齐问题
- heroku - ImportError: libGL.so.1 : 访问 Heroku 应用程序时出错
- asp.net-core - 访问我的项目根目录中的文件夹 - ASP.NET Core 3.1
- json - 使用 jq 将一个 JSON 中的值附加到另一个 JSON
- python - 熊猫:从列表中创建数据框,每个元素都有重复的日期
- c# - 如何实现多个 XML 根、多个元素名称
- pdflib - pdflib - 有没有办法判断字体是否支持中文
- html - 如何在引导程序中的两个文本框之间留出空间
- autohotkey - 匹配 AutoHotKey 中按下的两个 shift 键