关于json:UnrecognizedPropertyException:android中无法识别的字段错误

UnrecognizedPropertyException: Unrecognized field error in android

这是我的POJO课程。

1
2
3
4
5
6
7
8
9
10
11
12
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格式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[{
 "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。

1
2
3
4
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中可用。

我不明白为什么我的Capital案例字段会被转换成Smallcase?

为什么会出错? 怎么解决这个问题?


杰克逊反序列化:

  • 一个公共领域
  • 具有吸气剂或二传手的非公共场地