UnrecognizedPropertyException: Unrecognized field error in android

一笑奈何 提交于 2020-01-07 02:55:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!