【发布时间】:2016-10-20 00:09:36
【问题描述】:
这是我的 POJO 课程。
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 格式:
[{
"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"
}]
我正在尝试像这样使用这个 POJO。
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Product product = postSnapshot.getValue(Product.class);
products.add(product);
}
但我收到此错误:
原因: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: 无法识别的字段“BrandID”(com.example.sony.models.Product 类), 未标记为可忽略(9 个已知属性:、“brandID”、 “subCategoryName”、“productID”、“childItemList”、“variants”、 "productImagePath", "brandName", "subCategoryID", "productName"])
无法识别字段“BrandID”,但该字段在 POJO 中可用。
我不明白为什么我的大写字母字段被转换为小写字母?
为什么会出现这个错误?如何解决?
【问题讨论】:
-
@MD,感谢您的回复。但就我而言,所有字段都存在。所以我认为我不需要将它们标记为可忽略
-
您的 JSON 将 BrandID 作为字符串,而 POJO 将其作为 int。你可以试试把它改成字符串吗?
-
@basilisk,我尝试在 POJO 中将 BrandID 更改为字符串。但仍然是同样的错误。
-
查看错误,似乎json的字段名称为
brandID而不是BrandID。你能确认一下吗?
标签: android json firebase jackson pojo