Specifying custom property name when binding object to Web API endpoint

前端 未结 7 876

I have a .Net Core Web API. It automatically maps models when the model properties match the request body. For example, if you have this class:

public clas         


        
7条回答
  •  时光取名叫无心
    2020-12-09 15:51

    Change your package class and add JsonProperty decoration for each field you wish to map to a different json field.

    public class Package
    {
        [JsonProperty(PropertyName = "carrier")]
        public string Carrier { get; set; }
    
        [JsonProperty(PropertyName = "trackingNumber")]
        public string TrackingNumber { get; set; }
    }
    

提交回复
热议问题