Skip to content

Instantly share code, notes, and snippets.

@kirklewis
Created February 16, 2020 19:08
Show Gist options
  • Save kirklewis/2020f72b4b1fb3aad467cab0ccc2e49a to your computer and use it in GitHub Desktop.
Save kirklewis/2020f72b4b1fb3aad467cab0ccc2e49a to your computer and use it in GitHub Desktop.
Groovy 3.0 YamlSlurper
import groovy.yaml.YamlSlurper
def yamlSlurper = new YamlSlurper()
def yaml = yamlSlurper.parseText('''\
- 100
- 50
- 1
''')
assert yaml instanceof List
assert yaml == [100, 50, 1]
import groovy.yaml.YamlSlurper
def yamlSlurper = new YamlSlurper()
def yaml = yamlSlurper.parseText('''\
age: 25
name: "Mikasa"
languages:
- "English"
- "Japanese"
''')
assert yaml instanceof Map
assert yaml.name == 'Mikasa'
assert yaml.languages == ['English', 'Japanese']
import groovy.yaml.YamlSlurper
def yamlSlurper = new YamlSlurper()
def yaml = yamlSlurper.parseText('''\
name: amazon/aws-xray-daemon
tags:
- 3.2.0
- 3.1.0
''')
class DockerImage { String name; List tags; }
def image = new DockerImage(yaml)
assert image.name == 'amazon/aws-xray-daemon'
assert image.tags == ['3.2.0', '3.1.0']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment