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

Dev*_*wal 0 android json pojo jackson firebase

这是我的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(){}
}
Run Code Online (Sandbox Code Playgroud)

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"
}]
Run Code Online (Sandbox Code Playgroud)

我正在尝试像这样使用此POJO。

for (DataSnapshot postSnapshot : snapshot.getChildren()) {
    Product product = postSnapshot.getValue(Product.class);
    products.add(product);
}
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

引起原因:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段“ BrandID”(类com.example.sony.models.Product),未标记为可忽略(9个已知属性:,“ brandID”,“ subCategoryName” ,“ productID”,“ childItemList”,“ variants”,“ productImagePath”,“ brandName”,“ subCategoryID”,“ productName”])

无法识别的字段“ BrandID”,但该字段在POJO中可用。

我不明白为什么我的Capital Case字段被转换为Smallcase?

为什么会出现此错误?如何解决?

小智 5

杰克逊反序列化:

  • 公共领域
  • 使用getter或setter的非公共字段