下面是我的示例JSON數據。它在轉換過程中給出以下例外。還有另外一類有交易清單。JSON轉換問題
交易
public class Transactions{
private String id;
private ThisAccount thisAccount;
private OtherAccount otherAccount;
private Details details;
private Metadata metadata;
public String getId(){
return id;
}
public void setId(String input){
this.id = input;
}
public ThisAccount getThisAccount(){
return thisAccount;
}
public void setThisAccount(ThisAccount input){
this.thisAccount = input;
}
public OtherAccount getOtherAccount(){
return otherAccount;
}
public void setOtherAccount(OtherAccount input){
this.otherAccount = input;
}
public Details getDetails(){
return details;
}
public void setDetails(Details input){
this.details = input;
}
public Metadata getMetadata(){
return metadata;
}
public void setMetadata(Metadata input){
this.metadata = input;
}
public String toString() {
return this.getId();
}
}
JSON
{
"transactions":[
{
"id":"dcb8138c-eb88-404a-981d-d4edff1086a6",
"this_account":{
"id":"savings-kids-john",
"holders":[
{
"name":"Savings - Kids John",
"is_alias":false
}
],
"number":"832425-00304050",
"kind":"savings",
"IBAN":null,
"swift_bic":null,
"bank":{
"national_identifier":"rbs",
"name":"The Royal Bank of Scotland"
}
},
"other_account":{
"id":"c83f9a12-171e-4602-9a92-ae895c41b16b",
"holder":{
"name":"ALIAS_CBCDE5",
"is_alias":true
},
"number":"13677980653",
"kind":"CURRENT PLUS",
"IBAN":"BA12 1234 5123 4513 6779 8065 377",
"swift_bic":null,
"bank":{
"national_identifier":null,
"name":"The Bank of X"
},
"metadata":{
"public_alias":null,
"private_alias":null,
"more_info":null,
"URL":null,
"image_URL":null,
"open_corporates_URL":null,
"corporate_location":null,
"physical_location":null
}
},
"details":{
"type":"sandbox-payment",
"description":"Description abc",
"posted":"2016-10-09T20:01:53Z",
"completed":"2016-10-09T20:01:53Z",
"new_balance":{
"currency":"GBP",
"amount":null
},
"value":{
"currency":"GBP",
"amount":"10.00"
}
},
"metadata":{ }
},
{
"id":"06ffa118-7892-45c7-8904-f938766680dd",
"this_account":{ },
"other_account":{ },
"details":{ },
"metadata":{ }
},
{
"id":"2d633a56-cd59-4ee5-8dae-142750a1a1b4",
"this_account":{ },
"other_account":{ },
"details":{ },
"metadata":{ }
},
]
}
異常
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "this_account" (class com.transactionRetrieval.controller.Transactions), not marked as ignorable (5 known properties: "details", "id", "otherAccount", "thisAccount", "metadata"])
at [Source: [email protected]; line: 1, column: 79] (through reference chain: com.transactionRetrieval.controller.TransactionsList["transactions"]->java.util.ArrayList[0]->com.transactionRetrieval.controller.Transactions["this_account"])
它是否有做的變量名是thisAccount代替this_account什麼。有沒有一種方法來映射這個。有工作的方式嗎?