映射器的正确依赖集

映射器的正确依赖集

本文介绍了使用 Jackson 映射器的正确依赖集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Jackson 的新手,我正在编写一些用于练习的代码.我发现可以在 Fasterxml 上找到新版本的 Jackson 库:Jackson,所以我添加了以下内容对我的 Maven pom 文件的依赖:

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

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

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

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

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

我有点困惑.谁能告诉我这是为什么?

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

推荐答案

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

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

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

JsonFactory factory = objectMapper.getFactory();

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

因此,您在 pom 中已有的 3 个fasterxml"依赖项足以用于 ObjectMapper,因为它包含 jackson-databind.

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

这篇关于使用 Jackson 映射器的正确依赖集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 18:10