Using groovy yaml parser I need delete below lines and write into the file.
lines to remove.
- name: hostname
required: true
secure: false
valueExposed: true
When I try to load the yaml data to map. its failing with 'org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object ' exception.
I am looking help on. How to load this yaml data and remove 4 lines from it.
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
class Test {
def static main(args) {
DumperOptions options = new DumperOptions()
options.setPrettyFlow(true)
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
Yaml yaml = new Yaml(options)
def Map map = (Map) yaml.load(data)
println yaml.dump(map)
}
def static String data = '''
- description: checkc the disk spacce
executionEnabled: true
loglevel: INFO
name: disk spacce
options:
- description: file system name
name: filesystem
required: true
- name: hostname
required: true
secure: false
valueExposed: true
scheduleEnabled: true
sequence:
commands:
- exec: df -h
keepgoing: false
'''
}