【问题标题】:The type com.fasterxml.jackson.core.JsonGenerator cannot be resolved. It is indirectly referenced from required .class filescom.fasterxml.jackson.core.JsonGenerator 类型无法解析。它是从所需的 .class 文件中间接引用的
【发布时间】:2014-10-14 08:23:22
【问题描述】:

在这里,我在我的 eclipse 项目中使用 Jackson data binder 2.4.1 jar 库将对象转换为 json 格式。这是我的代码:

ObjectMapper mapper = new ObjectMapper();
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
mapper.writeValue(wr, content);

但在最后一行 mapper.writeValue(wr, content); 它给出了一个错误提示

The type com.fasterxml.jackson.core.JsonGenerator cannot be resolved. It is indirectly referenced from required .class files

我研究发现,当一个 jar 文件的类依赖于另一个不可用的类时,就会发生这种类型的错误。但是从我使用这个代码的地方 sn-p 没有这样的问题。但是我通过更改 JAR 版本失败了很多时间,但没有解决这个问题。怎么解决,求大神帮忙

【问题讨论】:

    标签: java eclipse jackson


    【解决方案1】:

    您的类路径中同时需要 jackson-databindjackson-core

    【讨论】:

      【解决方案2】:

      除了 jackson-databind 之外,将 jackson-core 添加到您的类路径中。

      步骤:

      1. here下载jackson-core JAR文件
      2. 右键单击项目并转到属性 > 构建路径 > 库 > 类路径
      3. 选择“添加外部 JAR”
      4. 选择文件位置
      5. 点击“应用并关闭”。

      【讨论】: