Java 使用 Jackson 映射器的正确依赖集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18429468/
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-12 01:33:28  来源:igfitidea点击:

Correct set of dependencies for using Hymanson mapper

javajsonHymanson

提问by Hossein

I am new to Hymanson and I was writing some code for practice. I found out the the new version of Hymanson library can be found on Fasterxml: Hymanson, so I added the below dependencies to my Maven pom file:

我是Hyman逊的新手,我正在编写一些练习代码。我发现新版本的 Hymanson 库可以在 Fasterxml: Hymanson上找到,所以我将以下依赖项添加到我的 Maven pom 文件中:

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

I was expecting that I can use the ObjectMapperdirectly, however after spending a lot of time I found out that to use the ObjectMapperI have to add the old libraries below:

我原以为可以ObjectMapper直接使用,但是花了很多时间后我发现要使用ObjectMapper我必须添加下面的旧库:

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

I am a bit confused. Could someone please tell me why is that?

我有点困惑。有人可以告诉我这是为什么吗?

回答by chenrui

The package names in Hymanson 2.x got changed to com.fasterxml1from org.codehaus2. So if you just need ObjectMapper, I think Hymanson 1.X can satisfy with your needs.

Hymanson 2.x 中的包名称从2更改为com.fasterxml1。所以如果你只需要ObjectMapper,我认为Hymanson 1.X 可以满足你的需求。org.codehaus

回答by specializt

No, you can simply use com.fasterxml.Hymanson.databind.ObjectMapper. Most likely you forgot to fix your import-statements, delete all references to codehaus and you're golden.

不,您可以简单地使用com.fasterxml.Hymanson.databind.ObjectMapper. 很可能您忘记修复您的import-statements,删除对 codehaus 的所有引用,然后您就成功了。

回答by ASD

<properties>
  <!-- Use the latest version whenever possible. -->
  <Hymanson.version>2.4.4</Hymanson.version>
</properties>
<dependencies>
   <dependency>
    <groupId>com.fasterxml.Hymanson.core</groupId>
    <artifactId>Hymanson-databind</artifactId>
    <version>${Hymanson.version}</version>
  </dependency>
</dependencies>

you have a ObjectMapper (from Hymanson Databind package) handy. if so, you can do:

你有一个方便的 ObjectMapper(来自 Hymanson Databind 包)。如果是这样,你可以这样做:

JsonFactory factory = objectMapper.getFactory();

Source: https://github.com/FasterXML/Hymanson-core

来源:https: //github.com/FasterXML/Hymanson-core

So, the 3 "fasterxml" dependencies which you already have in u'r pom are enough for ObjectMapper as it includes Hymanson-databind.

因此,您在 pom 中已经拥有的 3 个“fasterxml”依赖项对于 ObjectMapper 来说已经足够了,因为它包括 Hymanson-databind。

回答by QGA

I spent few hours on this.

我在这上面花了几个小时。

Even if I had the right dependency the problem was fixed only after I deleted the com.fasterxml.Hymanson folder in the .m2 repository under C:\Users\username.m2 and updated the project

即使我有正确的依赖关系,只有在我删除 C:\Users\username.m2 下 .m2 存储库中的 com.fasterxml.Hymanson 文件夹并更新项目后,问题才得到解决

回答by nilesh

Apart from fixing the imports, do a fresh maven clean compile -U. Note the -Uoption, that brings in new dependencies which sometimes the editor has hard time with. Let the compilation fail due to un-imported classes, but at least you have an option to import them after the maven command.

除了修复进口,做一个新鲜的maven clean compile -U. 请注意该-U选项,它会引入新的依赖项,有时编辑器很难处理这些依赖项。由于未导入的类而导致编译失败,但至少您可以选择在 maven 命令之后导入它们。

Just doing Maven->Reimport from Intellij did not work for me.

只是从 Intellij 执行 Maven->Reimport 对我不起作用。