Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
I need to convert json to pojo. I Decided to use jackson and have added jackson-core-2.2.0.jar, jackson-databind-2.4.4.jar and jackson-annotations-2.1.2.jar to my project's classpath
I created following Main
class:
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;
public class Json {
private static String SRC= "";
public static void main(String[] args) {
AwardList awardList = null;
ObjectMapper mapper = new ObjectMapper();
try{
awardList = (AwardList) mapper.readValue(new URL(SRC), AwardList.class);
}catch (JsonGenerationException e){
e.printStackTrace();
} catch (JsonMappingException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
System.out.println(awardList);
}
}
And following AwardList
class:
public class AwardList {
private Flights[] flights;
private String[] connections;
private SaverEconomy saverEconomy;
private StandartEconomy standartEconomy;
private SaverBusiness saverBusiness;
private StandartFirst standartFirst;
private SaverFirst saverFirst;
public Flights[] getFlights() {
return flights;
}
public void setFlights(Flights[] flights) {
this.flights = flights;
}
public SaverEconomy getSaverEconomy() {
return saverEconomy;
}
public void setSaverEconomy(SaverEconomy saverEconomy) {
this.saverEconomy = saverEconomy;
}
public StandartEconomy getStandartEconomy() {
return standartEconomy;
}
public void setStandartEconomy(StandartEconomy standartEconomy) {
this.standartEconomy = standartEconomy;
}
public SaverBusiness getSaverBusiness() {
return saverBusiness;
}
public void setSaverBusiness(SaverBusiness saverBusiness) {
this.saverBusiness = saverBusiness;
}
public StandartFirst getStandartFirst() {
return standartFirst;
}
public void setStandartFirst(StandartFirst standartFirst) {
this.standartFirst = standartFirst;
}
public SaverFirst getSaverFirst() {
return saverFirst;
}
public void setSaverFirst(SaverFirst saverFirst) {
this.saverFirst = saverFirst;
}
public String[] getConnections() {
return connections;
}
public void setConnections(String[] connections) {
this.connections = connections;
}
}
I want to convert json to pojo and save it in the database. I keep getting following error:
Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:457) at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:379) at Json.main(Json.java:72)
Solution 1:
I was getting the exactly same issue. I was using Maven for dependency management and had added dependency for jackson-databind module only like this
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
and then I resolved it by doing this.. I added its transitive dependencies explicitly with the same jackson.version mentioned for each of them in the pom.xml file, as guided here
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
Solution 2:
I came here with a similar issue on Google App Engine. Here is how I fixed it.
First I ran:
mvn dependency:tree
To find who is using the older version. I then excluded that from the offending dependency like so:
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>0.6</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
Next I added the newer version of the dependency in my pom.xml:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.7</version>
</dependency>
Hope this help others who stumble here.
Solution 3:
I had the same issue. There was some incompatibility between the jackson-version 2.6.3 and another dependency (graphaware-framework-embedded).
I could resolve the issue by simply removing the dependency on jackson in my own pom and just let the other dependency load whatever jackson-version it needed.