これは私のPOJOクラスです。UnrecognizedPropertyException:アンドロイドの認識できないフィールドエラー
public class Product implements ParentListItem {
private String ProductName;
private int ProductID;
private String ProductImagePath;
private String BrandName;
private int BrandID;
private String SubCategoryName;
private int SubCategoryID;
private List<ProductVariant> Variants = new ArrayList<>();
Product(){}
}
JSONフォーマット:私はこのように、このPOJOを使用しようとしています
[{
"Variants": [{
"VariantID": "1",
"VariantName": "50 GM",
"VariantImagePath": null,
"MRP": "19.00",
"SellPrice": "18.24",
"InCart": "0"
}],
"ProductName": "Body Cleanser - Lemon Honey Kanti",
"ProductID": "1",
"BrandName": "Patanjali",
"SubCategoryID": "44",
"SubCategoryName": "Bathing Soap",
"ProductImagePath": "\/images\/patanjali\/1819.png",
"BrandID": "112"
}]
。
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Product product = postSnapshot.getValue(Product.class);
products.add(product);
}
しかし、私はこのエラーを取得しています:
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "BrandID" (class com.example.sony.models.Product), not marked as ignorable (9 known properties: , "brandID", "subCategoryName", "productID", "childItemList", "variants", "productImagePath", "brandName", "subCategoryID", "productName"])
認識できないフィールド "BrandIDを" が、このフィールドはPOJOで利用可能です。
なぜ私の大文字小文字のフィールドが小文字に変換されているのですか?
このエラーはなぜですか?それを修正する方法は?
[http://stackoverflow.com/questions/4486787/jackson-with-json -unrecognized-field-not-ignorable](http://stackoverflow.com/questions/4486787/jackson-with-json-unrecognized-field-not-marked-as-ignorable) –
@MD、ありがとうございます応答。しかし、私の場合、すべてのフィールドが存在します。だから私はそれらを無視することが必要だとは思わない –
あなたのJSONはStringとしてBrandIDを持っていますが、POJOはintとしてそれを持っています。それをStringに変更できますか? – basilisk