找不到工件 Jackson-modules-java8:jar

Could not find artifact Jackson-modules-java8:jar

我用的是open-jdk-10.

mvn clean install

无法找到工件 com.fasterxml.jackson.module:jackson-modules-java8:jar:2.9.8 in" central"

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>group</groupId>
    <artifactId>artifact</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>10</maven.compiler.source>
        <maven.compiler.target>10</maven.compiler.target>
        <jackson.version>2.9.8</jackson.version>
    </properties>

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

        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-modules-java8</artifactId>
            <version>${jackson.version}</version>
        </dependency>
    </dependencies>

</project>

没有 jackson-modules-java8 它构建成功。

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-modules-java8</artifactId>
    <version>${jackson.version}</version>
</dependency>

有个的问题,但是没有解决我的问题。我的 pom 文件中有 maven 依赖项。如果没有别的办法,我最后会做的就是手动下载东西。

我删除了 java8-模块。

我改用

<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
    <version>${jackson.version}</version>
</dependency>

我不知道jackson-modules-java8jackson-datatype-jsr310有什么区别,但后者对我有用。

创建对象映射器时,注册JavaTimeModule

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());

在 GitHub jackson-datatype-jsr310 页面上您可以阅读:

(DEPRECATED) -- moved under jackson-modules-java8 repo: https://github.com/FasterXML/jackson-modules-java8

linked 页面上,您可以找到有关 java8 模块的信息:

Note that the parent project -- jackson-modules-java8 -- is ONLY used as parent pom by individual "child" modules, and DOES NOT have dependencies on them.

以及应该如何使用新模块:

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

Maven 存储库链接:

  1. jackson-datatype-jdk8
  2. All com.fasterxml.jackson.datatype modules