这是DTO C#类:
public class WeatherForecast
{
public string DateFormatted { get; set; }
}
这是招摇定义中生成的:
{"WeatherForecast":{"type":"object","properties":{"dateFormatted":{"type":"string"}}}}
问题是当我生成XML示例时:
<?xml version="1.0" encoding="UTF-8"?>
<WeatherForecast>
<dateFormatted>string</dateFormatted>
</WeatherForecast>
问题是,当我将该XML发送回API时,它没有填充DateFormatted属性。如果我更改大小写,使其不再是CamelCase(DateFormatted),它将正常工作,并且该属性将填充“字符串”。
生成摇摇欲坠的定义时如何关闭CamelCase?
答案 0 :(得分:1)
默认情况下,在aspnet中,骆驼属性名称如此,因此您将Startup
更改为
services.AddMvc();
到
services
.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
参考:aspnet