java - Issue with JSON conversion -


below sample json data. giving below exception during conversion. there class has list of transactions.

transactions

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":{  }       }, ] } 

exception

com.fasterxml.jackson.databind.exc.unrecognizedpropertyexception: unrecognized field "this_account" (class com.transactionretrieval.controller.transactions), not marked ignorable (5 known properties: "details", "id", "otheraccount", "thisaccount", "metadata"])  @ [source: java.io.stringreader@7d8ea76c; line: 1, column: 79] (through reference chain: com.transactionretrieval.controller.transactionslist["transactions"]->java.util.arraylist[0]->com.transactionretrieval.controller.transactions["this_account"]) 

does have variable name being thisaccount instead of this_account. there way map this. there way make work?

does have variable name being thisaccount instead of this_account.

yes, does.

is there way map this.

yes, point number 3

is there way make work?

yes, 3 of them can think right now


your json contains field called this_account, class doesn't, contains thisaccount.

there 3 ways solving this:

  1. change variable name to: this_account
  2. change json field thisaccount
  3. (recommended) use @jsonproperty annotation on thisaccount this:

    @jsonproperty("this_account") private thisaccount thisaccount; 

    this, "link" or "map" json property this_account variable thisaccount.

you need same thing rest of variables / fields in json , class have different name.

reference: https://github.com/fasterxml/jackson-annotations#annotations-for-renaming-properties


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -