Diese Frage ist eine Folge von dieser . Ich kann anscheinend nicht auf die Jackson-Bibliothek im folgenden Code zugreifen:
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);
}
}
die JAR-Dateien befinden sich jedoch im Klassenpfad (Autocomplete zeigt die Methodendeklaration in Intellij an).
Was vermisse ich?
Als ich dieses Problem hatte, hatte ich die jackson-annotations und jackson-databind jars in meinem Klassenpfad, aber nicht jackson-core .
Das Hinzufügen von Jackson-Core zum Klassenpfad hat es für mich gelöst.
Ich hatte auch das gleiche Problem, stellte sich heraus, ich hatte "jackson-core-asl.jar" anstelle von "jackson-core.jar"
Überprüfen Sie also, ob Sie diese JAR-Datei in Ihrem Klassenpfad haben .-> https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core