0

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?

Devesh Agrawal
  • 8,982
  • 16
  • 82
  • 131
  • [http://stackoverflow.com/questions/4486787/jackson-with-json-unrecognized-field-not-marked-as-ignorable](http://stackoverflow.com/questions/4486787/jackson-with-json-unrecognized-field-not-marked-as-ignorable) – M D Jun 18 '16 at 05:50
  • @MD, Thanks for response. But in my case all fields are present. So i don't think i need to mark them ignorable – Devesh Agrawal Jun 18 '16 at 05:53
  • Your JSON has BrandID as a String, whereas the POJO has it as an int. Can you try changing it to String? – Anuj Jun 18 '16 at 05:59
  • @basilisk, I tried changing BrandID as String in POJO. But still same error. – Devesh Agrawal Jun 18 '16 at 06:14
  • Looking at the error, it seems that the json has the field name as `brandID` instead of `BrandID`. Can you confirm? – Anuj Jun 18 '16 at 06:35
  • @basilisk, i re-verified JSON. Its BrandID only. Thing is how it is getting (9 known properties: , "brandID", "subCategoryName", "productID", "childItemList", "variants", "productImagePath", "brandName", "subCategoryID", "productName"]) This small letter start fields are neither in JSON nor in POJO. – Devesh Agrawal Jun 18 '16 at 06:44
  • Can you try to add the annotation `@JsonProperty("BrandID")` to the POJO field? – Anuj Jun 18 '16 at 07:15

1 Answers1

6

Jackson deserialize:

  • a public field
  • non-public field with getter or setter