Java Jackson 无法访问 com.fasterxml.jackson.core.ObjectCodec
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31356952/
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
Hymanson cannot access com.fasterxml.Hymanson.core.ObjectCodec
提问by Sebi
This question is a follow up to this one. I can't seem to be able to access the Hymanson library in the following code:
这个问题是一个跟进这一个。我似乎无法在以下代码中访问 Hymanson 库:
import com.fasterxml.Hymanson.databind.DeserializationFeature;
import com.fasterxml.Hymanson.databind.ObjectMapper;
import com.fasterxml.Hymanson.databind.ObjectReader;
import com.fasterxml.Hymanson.databind.ObjectWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ServerConfiguration {
public String info = null;
public String idlURL = null;
public String idlContents = null;
public List<ServerInfo> servers = new ArrayList<>();
public final void clear() {
info = null;
idlURL = null;
idlContents = null;
if (servers != null)
servers.clear();
}
private final static ObjectReader jsonReader;
private final static ObjectWriter jsonWriter;
static {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); // <== Error:(52, 15) java: cannot access com.fasterxml.Hymanson.core.JsonGenerator class file for com.fasterxml.Hymanson.core.JsonGenerator not found
//mapper.configure(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, true);
jsonWriter = mapper.writer();
jsonReader = mapper.reader(ServerConfiguration.class);
}
public static ServerConfiguration fromJson(String json) throws IOException {
return jsonReader.<ServerConfiguration>readValue(json); // <== Error:(59, 26) java: cannot access com.fasterxml.Hymanson.core.JsonProcessingException class file for com.fasterxml.Hymanson.core.JsonProcessingException not found
}
public String toJson() throws IOException {
return jsonWriter.writeValueAsString(this);
}
}
eventhough the jar files are in the classpath(autocomplete shows the method declaration in Intellij).
即使 jar 文件在类路径中(自动完成显示 Intellij 中的方法声明)。
What am I missing?
我错过了什么?
回答by gregn3
When I had this problem I had the Hymanson-annotationsand Hymanson-databindjars in my classpath, but not Hymanson-core.
当我遇到这个问题时,我的类路径中有Hymanson-annotations和Hymanson-databindjar,但没有Hymanson-core。
Adding Hymanson-core to the classpath solved it for me.
将 Hymanson-core 添加到类路径为我解决了这个问题。
回答by Yash P Shah
I had also encountered the same problem, turns out, I had "Hymanson-core-asl.jar" instead of "Hymanson-core.jar"
我也遇到了同样的问题,原来,我有“Hymanson-core-asl.jar”而不是“Hymanson-core.jar”
So, check whether you have this jar-file in your classpath. -> https://mvnrepository.com/artifact/com.fasterxml.Hymanson.core/Hymanson-core
因此,请检查您的类路径中是否有这个 jar 文件。-> https://mvnrepository.com/artifact/com.fasterxml.Hymanson.core/Hymanson-core
回答by Ayush Jaiswal
I was having a similar issue, it turned out to be an IntelliJ issue.
我遇到了类似的问题,结果是 IntelliJ 问题。
This helped me to resolve the issue:
这帮助我解决了这个问题:
Try File > Invalidate Caches > Invalidate and Restart
.
试试File > Invalidate Caches > Invalidate and Restart
。
If it doesn't help, delete .idea
directory and reimport from pom/gradle build file.
如果没有帮助,请删除.idea
目录并从 pom/gradle 构建文件重新导入。