本文介绍了杰克逊无法访问com.fasterxml.jackson.core.ObjectCodec的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此问题是对的跟进。 。我似乎无法在以下代码中访问jackson库:
This question is a follow up to this one. I can't seem to be able to access the jackson library in the following code:
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.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.jackson.core.JsonGenerator class file for com.fasterxml.jackson.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.jackson.core.JsonProcessingException class file for com.fasterxml.jackson.core.JsonProcessingException not found
}
public String toJson() throws IOException {
return jsonWriter.writeValueAsString(this);
}
}
尽管jar文件在classpath(autocomplete显示Intellij中的方法声明)。
eventhough the jar files are in the classpath(autocomplete shows the method declaration in Intellij).
我缺少什么?
推荐答案
当我遇到这个问题时我的类路径中有 jackson-annotations 和 jackson-databind 罐子,但不是 jackson-core 。
When I had this problem I had the jackson-annotations and jackson-databind jars in my classpath, but not jackson-core.
在类路径中添加jackson-core解决了它。
Adding jackson-core to the classpath solved it for me.
这篇关于杰克逊无法访问com.fasterxml.jackson.core.ObjectCodec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!