2017-06-11 18 views
-2

ジャクソンを使用してJson StringをJavaのObjectに変換するのが難しいです。Jackson Jsonリスト内のオブジェクト、Beanを取得するには?

モデル

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; 
} 

データ:

{ 
    "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 
} 

取得コード:

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

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

エラー:

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"]) 

質問:

どうしたのですか? 正しいコードはどのように書き込まれるべきですか?

私はHAVA Jackson Json List inside object ではなく、それは解決だまだ enter image description hereenter image description here

+0

Javaメンバー変数は、 'UpperCamelCase'ではなく' lowerCamelCase'でなければなりません。 –

+0

それはポイントではありません... – TTT

+1

それはあなたのエラーメッセージに基づいて、ほぼ確実に問題の一部です。 –

答えて

0

を定住を参照。 cricket_007

@ おかげで、私はこのように、フィールドに@JsonPropertyを追加、変更モデルを試しています

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; 
} 

ありがとうございました!

関連する問題