Intellij Idea JacksonYAML错误:TSFBuilder类未找到

zpgglvta  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(125)

我尝试使用Jackson(fasterxml)将字符串写入YAML文件,我使用IntelliJ IDEA社区版创建了一个Maven Java项目。然后我编辑了pom.xml如下:

<?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>org.merkgames</groupId>
    <artifactId>ChatGPT</artifactId>
    <version>1.0-SNAPSHOT</version>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-dataformat-yaml</artifactId>
                <version>2.7.0</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.16.0</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.16.0</version>
            </dependency>
    
        </dependencies>
    </dependencyManagement>
    
    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

字符串
在Main.java文件中,我将Main方法更改为如下所示:

public static void main(String[] args) throws IOException {

        ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
        String yamlString = "test: 1";
        Map<String, String> map = objectMapper.readValue(yamlString, Map.class);
    
        File file = new File("example.yml");
        objectMapper.writeValue(file, map);
    
    }


运行文件时出现以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/TSFBuilder
at org.merkgames.Main.main(Main.java:65)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.TSFBuilder
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 1 more

Process finished with exit code 1


有人能帮我吗?
看上面。所有的东西都列在那里。

ftf50wuq

ftf50wuq1#

您的jackson-dataformat-yaml已过时。请将其更新为2.16.0,应用程序应该可以运行。

相关问题