Java 无法解析 com.fasterxml.jackson.core.JsonGenerator 类型。它是从所需的 .class 文件间接引用的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25413842/
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
The type com.fasterxml.Hymanson.core.JsonGenerator cannot be resolved. It is indirectly referenced from required .class files
提问by Reyjohn
Here I am using Hymanson data binder 2.4.1 jar library in my eclipse project to convert an object to a json format. And here is my code:
在这里,我在我的 eclipse 项目中使用 Hymanson data binder 2.4.1 jar 库将对象转换为 json 格式。这是我的代码:
ObjectMapper mapper = new ObjectMapper();
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
mapper.writeValue(wr, content);
but in the last line mapper.writeValue(wr, content);
it gives an error saying
但在最后一行mapper.writeValue(wr, content);
它给出了一个错误说
The type com.fasterxml.Hymanson.core.JsonGenerator cannot be resolved. It is indirectly referenced from required .class files
I have studied and found that when a jar file's class is dependent on another class which is unavailable then this type of error occurs. But from where I am using this code snippet there is no issue like this. But I have failed a lot of time by changing the JAR version but nothing solved this issue. How can I solve this, please help
我研究并发现,当一个 jar 文件的类依赖于另一个不可用的类时,就会发生这种类型的错误。但是从我使用这个代码片段的地方来看,没有这样的问题。但是我通过更改 JAR 版本失败了很多时间,但没有解决这个问题。我该如何解决这个问题,请帮忙
采纳答案by Sotirios Delimanolis
You need both Hymanson-databind
and Hymanson-core
on your classpath.
你既需要Hymanson-databind
和Hymanson-core
你的类路径。
回答by Kms
Encountered the same issue when tried to convert JSONfile to Java POJOin eclipse using maven, using below databinddependency.
尝试使用 maven 在 Eclipse 中将JSON文件转换为 Java POJO时遇到同样的问题,使用以下数据绑定依赖项。
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.fasterxml.Hymanson.databind</artifactId>
<version>2.10.0.LIFERAY-PATCHED-1</version>
</dependency>
Solution:Removed the databinddependency and added only coredependency of Hymanson.
解决方案:去掉databind依赖,只添加Hymanson核心依赖。
<dependency>
<groupId>com.fasterxml.Hymanson.core</groupId>
<artifactId>Hymanson-databind</artifactId>
<version>2.0.0</version>
</dependency>