没有提供值时,List <Enum>无法反序列化

在一个类帐户中,房地产行业是枚举类型行业的集合

一个帐户可以属于多个行业。

public class account
{

[JsonProperty(ItemConverterType = typeof(StringEnumConverter))]
public List<Industry> Industrys { get; set; } 

}

Public enum Industry
{
AerospaceAirlines = 0,Agriculture = 1,Apparel = 2,Automotive = 3,Banking = 4,BioTechnology = 5,Chemicals = 6,Communications = 7,Construction = 8,Consultancy = 9,ConsumerDurables = 10,Education = 11,}

创建新帐户时,添加行业不是强制性的。如果在此行业属性的请求对象中未提供任何值,则失败。

从反序列化出现错误:“值不能为空。\ r \ n参数名称:source”

当默认活页夹试图填充accountModel对象时,将发生失败。

[HttpPost]
        public async Task<IactionResult> Post([FromBody]accountModel accountModel)
        {
            if (accountModel == null)
            {
                throw new ApiException(ApplicationErrorCode.FieldRequiredError,"request cannot be empty");
            }
       }

在没有提供行业信息的情况下,如何允许发送方发送请求?

lwb896148823 回答:没有提供值时,List <Enum>无法反序列化

更改:

public class Account
{

[JsonProperty(ItemConverterType = typeof(StringEnumConverter))]
public List<Industry> Industrys { get; set; } 

}

收件人:

public class Account
{

[JsonProperty(ItemConverterType = typeof(StringEnumConverter))]
public List<Industry> Industrys { get; set; } = new List<Industry>();

}
本文链接:https://www.f2er.com/3158292.html

大家都在问