问题
This is my POJO class.
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 format:
[{
"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"
}]
I am trying to use this POJO like this.
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Product product = postSnapshot.getValue(Product.class);
products.add(product);
}
But i am getting this error:
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"])
Unrecognized field "BrandID" , but this field is available in POJO.
I don't understand why my Capital case field are getting converted into Smallcase?
Why is this error? how to fix that?
回答1:
Jackson deserialize:
- a public field
- non-public field with getter or setter
来源:https://stackoverflow.com/questions/37893680/unrecognizedpropertyexception-unrecognized-field-error-in-android