Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jackson cannot access com.fasterxml.jackson.core.ObjectCodec

Tags:

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);     }  } 

eventhough the jar files are in the classpath(autocomplete shows the method declaration in Intellij).

What am I missing?

like image 388
Sebi Avatar asked Jul 11 '15 11:07

Sebi


People also ask

What is ObjectCodec in Java?

public abstract class ObjectCodec extends TreeCodec implements Versioned. Abstract class that defines the interface that JsonParser and JsonGenerator use to serialize and deserialize regular Java objects (POJOs aka Beans). The standard implementation of this class is com.

What is the use of Jackson annotations?

Jackson Annotations - @JacksonInject @JacksonInject is used when a property value is to be injected instead of being parsed from Json input. In the example below, we are inserting a value into object instead of parsing from the Json.

What is the latest version of Jackson?

Active developed Jackson 2.2.14 : next minor version being developed (as of May 2022) 2.13 : current stable, actively maintained branch from which one more patch release is possible.

What is Jackson parser?

Jackson JSON Parser API provides easy way to convert JSON to POJO Object and supports easy conversion to Map from JSON data. Jackson supports generics too and directly converts them from JSON to object.


1 Answers

When I had this problem I had the jackson-annotations and jackson-databind jars in my classpath, but not jackson-core.

Adding jackson-core to the classpath solved it for me.

like image 172
gregn3 Avatar answered Sep 25 '22 09:09

gregn3