UnrecognizedPropertyException:android中无法识别的字段错误 [英] UnrecognizedPropertyException: Unrecognized field error in android

查看:474
本文介绍了UnrecognizedPropertyException:android中无法识别的字段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的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。

I am trying to use this POJO like this.

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])

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中可用。

Unrecognized field "BrandID" , but this field is available in POJO.

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

I don't understand why my Capital case field are getting converted into Smallcase?

为什么会出现此错误?如何解决这个问题?

Why is this error? how to fix that?

推荐答案

杰克逊反序列化:


  • 公共字段

  • 带有getter或setter的非公共字段

这篇关于UnrecognizedPropertyException:android中无法识别的字段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆