升级库版本后Eclipse编译器错误

时间:2014-03-03 22:15:46

标签: java json jackson

我有Jackson 1.8.2,除了嵌套的geo_position属性外,一切正常。

在浏览了一些SO问题之后,我已升级到Jackson 1.9.x,现在Jackson设法识别位置嵌套类,但抱怨纬度原始浮动属性。

此外,当我在升级到新的Jackson版本后尝试编译项目时,eclipse发出了一个奇怪的错误: 尝试降级回到1.8.2,但没有运气。 这有什么奇怪的,没有实际的错误,项目的验证也很顺利。

enter image description here

堆栈追踪:

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "latitude" (Class task.Position), not marked as ignorable
 at [Source: java.io.StringReader@14de991; line: 1, column: 64] (through reference chain: task.ResultSet["results"]->task.Location["geo_position"]->task.Position["latitude"])null

at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)
at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)
at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)
at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)
at org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)
at org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)
at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:194)
at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:30)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)
at org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2732)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)
at task.JSONParser.fromNative(JSONParser.java:24)
at task.RESTClient.main(RESTClient.java:85)

代码: https://github.com/BeOleg/JavaRestClient

2 个答案:

答案 0 :(得分:1)

您需要使用task.Position注释@JsonIgnoreProperties以忽略您不想要的属性。

Unrecognized field "latitude" (Class task.Position), not marked as ignorable

答案 1 :(得分:0)

事实证明,在位于项目根目录的.classpath文件中,eclipse离开了旧版本的core-jackson jar,与新版本一起,这导致了所有错误!

下次我必须使用Java时,我真的要使用intelli-j ...

<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="lib" path="lib/commons-codec-1.6.jar"/>
    <classpathentry kind="lib" path="lib/commons-logging-1.1.3.jar"/>
    <classpathentry kind="lib" path="lib/fluent-hc-4.3.2.jar"/>
    <classpathentry kind="lib" path="lib/httpclient-4.3.2.jar"/>
    <classpathentry kind="lib" path="lib/httpclient-cache-4.3.2.jar"/>
    <classpathentry kind="lib" path="lib/httpcore-4.3.1.jar"/>
    <classpathentry kind="lib" path="lib/httpmime-4.3.2.jar"/>
    //Just erased bellow line:
    <classpathentry kind="lib" path="lib/jackson-core-asl-1.8.2.jar"/>
    <classpathentry kind="lib" path="lib/jackson-core-asl-1.9.13.jar"/>
    <classpathentry kind="lib" path="lib/jackson-mapper-asl-1.9.13.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

@Yuri Prezument的所有学分:D