我正在尝试将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"
1条答案
按热度按时间bqf10yzr1#
依赖关系问题,以下依赖关系有效