json - 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 的属性,它是一个对象。脱硫器会因此而感到困惑吗?
- 那么我该如何解决这个问题?任何解决方案都会很棒,但请记住,所有这些模型都是从 yaml 文件生成的代码,因此最好的解决方案是不会干扰模型的东西,因为它们将在下一次构建时重新生成。谢谢!
解决方案
推荐阅读
- postgresql - 使用 sequelize 连接 Postgresql 数据库
- delphi - 为什么类型名称_Recordset 中有下划线?
- ios - 快速从url下载pdf并将其保存到文件中
- math - 分解 99 位长的大素数的问题
- java - Google Tink 混合参数
- c# - 用于测试嵌入式 SQL 的 C# NUnit 模拟数据库设置
- mysql - 如何获得季度剩余天数
- google-cloud-platform - 有没有办法将谷歌云平台中的虚拟机内容备份到特定的存储桶?
- php - 日期过滤器不适用于php中的mysql
- jdbc - java.Sql.SQLException,无法加载类 net.ucanaccess.jdbc.UcanaccessDriver