Java org.codehaus.jackson.map.exc.UnrecognizedPropertyException:无法识别的字段“id”(类标准),未标记为可忽略
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22391213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
org.codehaus.Hymanson.map.exc.UnrecognizedPropertyException: Unrecognized field "id" (Class Criteria), not marked as ignorable
提问by Oliver.Oakley
I am getting this exception when I am trying to parse Json to Java pojo object. The object graph has couple objects.
当我尝试将 Json 解析为 Java pojo 对象时出现此异常。对象图有几个对象。
org.codehaus.Hymanson.map.exc.UnrecognizedPropertyException: Unrecognized field "id" (Class Criteria), not marked as ignorable
I wanted to see, in which case this exception will come, where could be the problem is it in the object graph??
我想看看,在这种情况下会出现这个异常,对象图中的问题可能出在哪里??
I am doing this in my android project I am not using annotations here I am not sure how to add this field as ignorable.
我在我的 android 项目中这样做我没有在这里使用注释我不知道如何将此字段添加为可忽略的。
回答by fge
You don't show any code, so...
你没有显示任何代码,所以......
Anyway, try and add this annotation to the class you deserialize:
无论如何,尝试将此注释添加到您反序列化的类中:
@JsonIgnoreProperties(ignoreUnknown=true)
回答by NathanChristie
This will also happen if you have defined the field in your POJO, but do not have a getter AND setter methods defined. Ignoring the field may have unintended consequences.
如果您在 POJO 中定义了字段,但没有定义 getter 和 setter 方法,也会发生这种情况。忽略该字段可能会产生意想不到的后果。
This does look to be a duplicate of: Hymanson with JSON: Unrecognized field, not marked as ignorable
这看起来确实与以下内容重复:Hymanson with JSON: Unrecognized field, not tags as ignorable