📜  writeYaml - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:39.240000             🧑  作者: Mango

代码示例1
@Grab('org.yaml:snakeyaml:1.17')
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.DumperOptions
import static org.yaml.snakeyaml.DumperOptions.FlowStyle.BLOCK

node {
    def yaml = readYaml file: "test.yml"
    yaml.data.info = 'hello world!'
    writeFile file:"test.yml", text:yamlToString(yaml)
}

@NonCPS
String yamlToString(Object data){
    def opts = new DumperOptions()
    opts.setDefaultFlowStyle(BLOCK)
    return new Yaml(opts).dump(data)
}