Jackson具有支持YAML的模块。确保将必需的依赖项添加到项目中,然后可以按以下方式使用它:
// Create an ObjectMapper mapper for YAMLObjectMapper mapper = new ObjectMapper(new YAMLFactory());// Write object as YAML filemapper.writevalue(new File("/path/to/yaml/file"), example);或者,您可以将对象写为字符串:
// Write object as YAML stringString yaml = mapper.writevalueAsString(example);



