Created
February 16, 2020 19:08
-
-
Save kirklewis/2020f72b4b1fb3aad467cab0ccc2e49a to your computer and use it in GitHub Desktop.
Groovy 3.0 YamlSlurper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.yaml.YamlSlurper | |
def yamlSlurper = new YamlSlurper() | |
def yaml = yamlSlurper.parseText('''\ | |
- 100 | |
- 50 | |
- 1 | |
''') | |
assert yaml instanceof List | |
assert yaml == [100, 50, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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