首页 > 解决方案 > Json 没有正确解散

问题描述

我需要连接到某个 API,所以我使用他们的 API 文档来生成 API 调用客户端和模型,以便我可以使用他们的 API。但是,他们的一个电话似乎给了我一个错误。调用该特定 API 端点时,响应如下所示

 {
      "Data": {
        "Account": [
          {
            "AccountId": "111001",
            "Currency": "GBP",
            "AccountType": "Personal",
            "AccountSubType": "CurrentAccount",
            "Nickname": "Bills",
            "Account": {
              "SchemeName": "UK.OBIE.SortCodeAccountNumber",
              "Identification": "80200110203345",
              "Name": "Mr Kevin",
              "SecondaryIdentification": "00021"
            }
          },
          {
            "AccountId": "111002",
            "Currency": "GBP",
            "AccountType": "Personal",
            "AccountSubType": "CurrentAccount",
            "Nickname": "Household",
            "Account": {
              "SchemeName": "UK.OBIE.SortCodeAccountNumber",
              "Identification": "80200110203348",
              "Name": "Mr Kevin"
            }
          }
        ]
      },
      "Links": {
        "Self": "https://blablabla.com"
      },
      "Meta": {
        "TotalPages": 1
      }
    }

用于反序列化此响应的模型是

public class AccountResponseDtoClassUsedToDeserilizeProperly {
        @JsonProperty("Data")
        private Data data;
        @JsonProperty("Links")
        private Links links;
        @JsonProperty("Meta")
        private Meta meta;
    }

 public class Data {
        @JsonProperty("Account")
        private List<Account> account = null;
}

 public class Account {



@JsonProperty("AccountId")
    private String accountId;
    @JsonProperty("Currency")
    private String currency;
    @JsonProperty("AccountType")
    private String accountType;
    @JsonProperty("AccountSubType")
    private String accountSubType;
    @JsonProperty("Nickname")
    private String nickname;
    @JsonProperty("Account")
    private Account_ account;
}

public class Account_ {
   @JsonProperty("SchemeName")
        private String schemeName;
        @JsonProperty("Identification")
        private String identification;
        @JsonProperty("Name")
        private String name;
        @JsonProperty("SecondaryIdentification")
        private String secondaryIdentification;
    }

一些不重要的模型被遗漏了。

尝试反序列化时,这是我收到的错误:

java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 149 path $.Data.Account[0].Account

我对这个问题的怀疑是: 在模型Data中有一个属性名称帐户是一个列表。

在模型Account中有一个名为 Account 的属性,它是一个对象。脱硫器会因此而感到困惑吗?

标签: jsonserializationgsondeserializationjson-deserialization

解决方案


推荐阅读