RestSharp ExecAsync<T> 其中 T 是嵌套对象

RestSharp ExecAsync<T> where T is a nested object

我有一个调用 RestSharp 客户端 ExecuteAsync<T> 的方法,其中我传递的 T 是一个嵌套对象。我得到一个异常

InvalidProgramException: Request for the resource /v1/accounts/AN_1476935163870 failed No parameterless constructor defined for this object.

我传递的对象是:

public class GetAccountResponse : IGetAccountResponse
    {
        public GetAccountResponseBasicInfo basicInfo { get; set; }
        public GetAccountResponseBillingAndPayment billingAndPayment { get; set; }
        public GetAccountResponseMetrics metrics { get; set; }
        public string billToContact { get; set; }
        public string soldToContact { get; set; }
        public bool success { get; set; }
    }

属性 basicInfobillingAndPayment 和指标的对象 类 具有定义,但我没有定义构造函数。我也试过用接口替换对象,但它仍然抛出异常。

谢谢

这个问题可能有两个原因:

  • RestSharp 中的回归向类型化请求方法添加了 new 约束,这已于本周修复
  • 序列化问题。在这种情况下,您可以尝试另一个序列化程序,除了内置的 SimpleJson
  • 之外,我们还有支持 NewtosoftJson、Utf8Json 和 System.Text.Json 的库