-2

I am having difficulties transforming a Json String into an Object in java using Jackson.

Model

public class PPDResult {


    int Result;
    String ResultMessage;

    List<PPDObj> LoanInfos;
}

public class PPDObj {

    private int ListingId;

    private String Title;

    private String CreditCode;

    private BigDecimal Amount;

    private Double Rate;

    private int Months;

    private int PayWay;

    private BigDecimal RemainFunding;
}

Data:

{
    "LoanInfos": [
        {
            "ListingId": 52233312,
            "Title": "xxxxxxx",
            "CreditCode": "D",
            "Amount": 787,
            "Rate": 22,
            "Months": 6,
            "PayWay": 0,
            "RemainFunding": 387
        },
        {
            "ListingId": 52233362,
            "Title": "xxxxxxxxx",
            "CreditCode": "B",
            "Amount": 10000,
            "Rate": 18,
            "Months": 6,
            "PayWay": 0,
            "RemainFunding": 7695
        }
    ],
    "Result": 1,
    "ResultMessage": "success",
    "ResultCode": null
}

Retrieve code:

String resultStr = new BufferedReader(inputStreamReader).readLine();        

pPDResult = mapper.readValue(resultStr, PPDResult.class);

Error:

Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "LoanInfos" (class ppd.pojo.PPDResult), not marked as ignorable (3 known properties: , "resultMessage", "result", "loanInfos"])
 at [Source: xxxxxxxxx; line: 1, column: 15] (through reference chain: ppd.pojo.PPDResult["LoanInfos"])

Questions:

What is wrong? How should the correct code be written?

I hava reference Jackson Json List inside object but not settled yet enter image description hereenter image description here

TTT
  • 11
  • 3

1 Answers1

0

It's resolve. Thanks @cricket_007

I have try change model ,add @JsonProperty to field ,like this:

public class PPDObj {

    @JsonProperty("ListingId")
    private int ListingId;
    @JsonProperty("Title")
    private String Title;
    @JsonProperty("CreditCode")
    private String CreditCode;
    @JsonProperty("Amount")
    private BigDecimal Amount;
    @JsonProperty("Rate")
    private Double Rate;
    @JsonProperty("Months")
    private int Months;
    @JsonProperty("PayWay")
    private int PayWay;
    @JsonProperty("RemainFunding")
    private BigDecimal RemainFunding;

}
public class PPDResult {

    @JsonProperty("Result")
    int Result;
    @JsonProperty("ResultMessage")
    String ResultMessage;
    @JsonProperty("ResultCode")
    String ResultCode;
    @JsonProperty("LoanInfos")
    List<PPDObj> LoanInfos;
}

Thank you !

TTT
  • 11
  • 3