线程“main”中出现异常java.lang.NoSuchMethodError:com.fasterxml.Jackson.core.JsonFactory.requiresPropertyOrdering()Z

f8rj6qna  于 2023-10-20  发布在  Java
关注(0)|答案(7)|浏览(140)

我需要把json转换成pojo。我决定使用Jackson,并将jackson-core-2.2.0.jar、jackson-databind-2.4.4.jar和jackson-annotations-2.1.2.jar添加到项目的类路径中
我创建了Main类:

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

  }
}

AwardList类:

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

我想将json转换为pojo并保存到数据库中。我一直得到以下错误:

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)
n9vozmp4

n9vozmp41#

我也收到了同样的问题。我使用Maven进行依赖项管理,并且只像这样添加了jackson-databind模块的依赖项

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>${jackson.version}</version>
</dependency>

然后我就这样解决了我显式地添加了它的传递依赖项,并在pom.xml文件中为它们中的每一个添加了相同的Jackson.version,如下所示

<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>
fsi0uk1n

fsi0uk1n2#

我在Google App Engine上遇到了类似的问题。这就是我如何修复它。
我先跑:

mvn dependency:tree

找出谁在使用旧版本。然后我把它从令人讨厌的依赖关系中排除出来,就像这样:

<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>

接下来,我在pom.xml中添加了新版本的依赖项:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.8.7</version>
</dependency>

希望这能帮助那些在这里跌倒的人。

bxgwgixi

bxgwgixi3#

我也有同样的问题。jackson-version 2.6.3和另一个依赖项(graphaware-framework-embedded)之间存在一些不兼容性。

    • 我可以解决这个问题,只要在我自己的pom中删除对jackson的依赖**,让其他依赖加载它需要的任何jackson版本。
t1qtbnec

t1qtbnec4#

截至目前,最新redisson

<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson</artifactId>
    <version>3.13.4</version>
</dependency>

最新的Jackson.版本属性是2.11.2对我来说

<!-- faster JSON -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <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>

更新Eclipse引用,如果没有此运行程序,则将访问Jackson项目的早期版本。

eclipse:eclipse -U
u91tlkcl

u91tlkcl5#

我刚刚在将我的项目从spring 3升级到4.1.6时遇到了同样的问题。
一个小的背景参考,以防万一,如果它有助于任何人遇到同样的问题=>首先,它提示我与错误mappingJacksonconverter与mappingJackson 2converter,因为前者不存在了Spring4。一旦我在代码中更改了这些引用,我就遇到了调度器servlet的问题,因为它有spring 3支持的xsd定义。一旦这一点得到纠正,我在旅程中的最后一步是这个错误,你们都面临着以及。
我的解决方案:我有以下jar的旧版本:jackson-annotations,jackson-core,jackson-databind,jackson-core-asl,jackson-mapper-asl
我将前3个jar升级到2.10.0.pr1版本,最后2个升级到1.9.13版本。
我还有一个更老的jar,也就是我不得不删除的com.fasterxml.jackson.core.jar。无论如何,正如错误表明这是不匹配的关键原因(就像Tobias在我之前的评论中所说的那样)
我认为只有最后一段是重要的,从这个特定的问题的Angular 来看,但我希望我的叙述所面临的问题,导致这可能有助于有人节省4-5小时:)干杯,乡亲!

4xrmg8kj

4xrmg8kj6#

对我来说,我更新了版本到最近发布的版本,即。2.12.4它运行良好。
注意:我使用的是Eclipse中一个更大项目的构建路径中的另一个项目。Jackson更新是在较小项目的pom.xml文件中完成的。

wwwo4jvm

wwwo4jvm7#

由于旧版本的漏洞,我已经将maven项目中的Jackson依赖版本从2.7.4更新为2.15.0。更新后,我得到一个异常NoClassDefFoundError。我尝试使用JacksonBOM 2.15.0,但仍然得到该异常。如何解决此异常?

Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructors(Class.java:1651)
at org.apache.felix.scr.impl.inject.ComponentConstructor.<init>(ComponentConstructor.java:95) [org.apache.felix.scr:2.1.16]
at org.apache.felix.scr.impl.inject.ComponentMethodsImpl.initComponentMethods(ComponentMethodsImpl.java:106) [org.apache.felix.scr:2.1.16]
at org.apache.felix.scr.impl.manager.AbstractComponentManager.initDependencyManagers(AbstractComponentManager.java:1008) [org.apache.felix.scr:2.1.16]
at org.apache.felix.scr.impl.manager.AbstractComponentManager.collectDependencies(AbstractComponentManager.java:1026) [org.apache.felix.scr:2.1.16]
at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:935) [org.apache.felix.scr:2.1.16]
at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:900) [org.apache.felix.scr:2.1.16]
at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:348)
... 52 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException not found by com.dunkindonuts.aem.ddcom-ui-businesslogic [791]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1597)
at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1982)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)

相关问题