jackson 将java对象作为YAML文件写入时,不应调用方法

8zzbczxx  于 2022-11-08  发布在  Java
关注(0)|答案(1)|浏览(145)

我正在尝试将Java对象写为YAML文件。并得到下面的异常。有什么指针来修复这个问题吗?

代码

public void writeRequestRoot(RequestRoot requestRoot, String fileName) {
            ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
            try {
                mapper.writeValue(new File("fileName), requestRoot);
            } catch (IOException e) {
                e.printStackTrace();
                throw new RuntimeException(e.getMessage());
            }
        }

日志

Method should never get called
    java.lang.IllegalStateException: Method should never get called
        at com.fasterxml.jackson.dataformat.yaml.YAMLFactory._createUTF8Generator(YAMLFactory.java:575)
        at com.fasterxml.jackson.dataformat.yaml.YAMLFactory._createUTF8Generator(YAMLFactory.java:15)
        at com.fasterxml.jackson.core.JsonFactory.createGenerator(JsonFactory.java:1228)
        at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3351)
        at com.scb.nexus.beats.helper.YamlReaderWriter.writeRequestRoot(YamlReaderWriter.java:45)

相依性

implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.1.2"
bqf10yzr

bqf10yzr1#

依赖关系问题,以下依赖关系有效

implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.3"

相关问题