java.lang.ClassNotFoundException: com.fasterxml.jackson.annotation.JsonInclude$Value

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35569092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 16:50:32  来源:igfitidea点击:

java.lang.ClassNotFoundException: com.fasterxml.Hymanson.annotation.JsonInclude$Value

javaHymansonwordpress-json-api

提问by user327126

I am trying to convert my json string to java object and I am getting error

我正在尝试将我的 json 字符串转换为 java 对象,但出现错误

Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/Hymanson/annotation/JsonInclude$Value at com.fasterxml.Hymanson.databind.cfg.MapperConfig.(MapperConfig.java:45) at com.fasterxml.Hymanson.databind.ObjectMapper.(ObjectMapper.java:535) at com.fasterxml.Hymanson.databind.ObjectMapper.(ObjectMapper.java:452) at com.allianz.cmis.util.ApacheHttpClientGet.main(ApacheHttpClientGet.java:65) Caused by: java.lang.ClassNotFoundException: com.fasterxml.Hymanson.annotation.JsonInclude$Value at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 4 more

线程“main”中的异常 java.lang.NoClassDefFoundError: com/fasterxml/Hymanson/annotation/JsonInclude$Value at com.fasterxml.Hymanson.databind.cfg.MapperConfig.(MapperConfig.java:45) at com.fasterxml.Hymanson。 databind.ObjectMapper.(ObjectMapper.java:535) at com.fasterxml.Hymanson.databind.ObjectMapper.(ObjectMapper.java:452) at com.allianz.cmis.util.ApacheHttpClientGet.main(ApacheHttpClientGet.java:65) : java.lang.ClassNotFoundException: com.fasterxml.Hymanson.annotation.JsonInclude$Value at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355)在 java.security.AccessController.doPrivileged(Native Method) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:354) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:425) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 4 更多

Here is my json string and my code snippet

这是我的 json 字符串和我的代码片段

json string {'ctpnsw': [{'abc' , 'def' }]}

json字符串 {'ctpnsw': [{'abc' , 'def' }]}

model

模型

public class Fields {

     private List<String> ctpnsw;

    public List<String> getCtpnsw() {
        return ctpnsw;
    }

    public void setCtpnsw(List<String> ctpnsw) {
        this.ctpnsw = ctpnsw;
    }

}

Java code

Java代码

ObjectMapper mapper = new ObjectMapper(); List<Fields> list = mapper.readValue(output, TypeFactory.defaultInstance().constructCollectionType(List.class,Fields.class)); System.out.println(list);

ObjectMapper mapper = new ObjectMapper(); List<Fields> list = mapper.readValue(output, TypeFactory.defaultInstance().constructCollectionType(List.class,Fields.class)); System.out.println(list);

回答by Marcus K.

I had the same error message. In my case, Hymanson consisted of multiple JAR files. Sadly, they had different versions of Hymanson-core and Hymanson-annotations which resulted in the above exception.

我有同样的错误信息。就我而言,Hymanson 由多个 JAR 文件组成。可悲的是,他们有不同版本的 Hymanson-core 和 Hymanson-annotations,这导致了上述异常。

Maybe you don't have the Hymanson-annotation JAR in your classpath, at least not in the correct version. You can analyze the used library versions with the command mvn dependency:tree.

也许您的类路径中没有 Hymanson-annotation JAR,至少在正确的版本中没有。您可以使用命令分析使用的库版本mvn dependency:tree

回答by MonoThreaded

How about adding this to your pom.xml

如何将它添加到您的 pom.xml

<dependency>
    <groupId>com.fasterxml.Hymanson.core</groupId>
    <artifactId>Hymanson-annotations</artifactId>
    <version>${Hymanson.version}</version>
</dependency>

回答by Vino

Hymanson marshalling/unmarshalling requires following jar files of same version.

Hymanson 编组/解组需要以下相同版本的 jar 文件。

  1. Hymanson-core

  2. Hymanson-databind

  3. Hymanson-annotations

    Make sure that you have added all these with same version in your classpath. In your case Hymanson-annotationsis missing in classpath.

  1. Hyman逊核心

  2. Hyman逊数据绑定

  3. Hyman逊注释

    确保您在类路径中添加了所有这些具有相同版本的内容。在您的情况下,类路径中缺少Hymanson-annotations

回答by Baked Inhalf

Get all 3 Hymanson jars and add them to your build path:

获取所有 3 个 Hymanson jar 并将它们添加到您的构建路径中:

https://mvnrepository.com/artifact/com.fasterxml.Hymanson.core

https://mvnrepository.com/artifact/com.fasterxml.Hymanson.core

回答by Jijun Jiang

this is a version problem change version > 2.4 to 1.9 solve it

这是一个版本问题,将版本> 2.4 更改为 1.9 解决它

<dependency>  
<groupId>com.fasterxml.Hymanson.jaxrs</groupId>  
<artifactId>Hymanson-jaxrs-xml-provider</artifactId>  
<version>2.4.1</version>  

to

<dependency>  
<groupId>org.codehaus.Hymanson</groupId>  
<artifactId>Hymanson-mapper-asl</artifactId>  
<version>1.9.4</version>  

回答by Pramod Itagi

Use Hymanson-bom which will have all the three Hymanson versions.i.e.Hymanson-annotations, Hymanson-core and Hymanson-databind. This will resolve the dependencies related to those versions

使用 Hymanson-bom,它将包含所有三个 Hymanson 版本。ieHymanson-annotations、Hymanson-core 和 Hymanson-databind。这将解决与这些版本相关的依赖关系

回答by Piumal Kulasekara

Even though this answer was too late, I'm adding it because I also went through a horrible time finding answer for the same matter. Only different was, I was struggling with AWS Comprehend Medical API.

即使这个答案为时已晚,我还是要添加它,因为我也经历了为同一问题寻找答案的可怕时间。唯一不同的是,我一直在努力使用 AWS Comprehend Medical API。

At the moment I'm writing this answer, if anyone come across the same issue with any AWS SDKs please downgrade Hymanson-annotaions or any Hymanson dependencies to 2.8.* versions.The latest 2.9.* versions does not working properly with AWS SDK for some reason. Anyone have any idea about the reason behind that feel free to comment below.

目前我正在写这个答案,如果有人在使用任何 AWS 开发工具包时遇到同样的问题,请将Hymanson-annotations 或任何 Hymanson 依赖项降级到 2.8.* 版本。由于某种原因,最新的 2.9.* 版本无法与 AWS SDK 正常工作。任何人对此背后的原因有任何想法,请随时在下面发表评论。

Just in case if anyone is lazy to google maven repos, I have linked down necessary repos.Check them out!

以防万一如果有人懒于谷歌 Maven 存储库,我已经链接了必要的存储库。检查出来!

回答by Saurabh

I had different version of annotations jar. Changed all 3 jars to use SAME versionof databind,annotations and core Hymanson jars

我有不同版本的注释 jar。将所有 3 个 jar 更改为使用相同版本的数据绑定、注释和核心 Hymanson jar

<dependency>
        <groupId>com.fasterxml.Hymanson.core</groupId>
        <artifactId>Hymanson-annotations</artifactId>
        <version>2.8.6</version>
</dependency>

回答by Satya Prakash

Use Hymanson-annotations.jar will solve the problem, as it worked for me.

使用 Hymanson-annotations.jar 将解决问题,因为它对我有用。