Created
February 16, 2020 19:09
-
-
Save kirklewis/e7dd2f9402679c4c36d4132d4f28b2ee to your computer and use it in GitHub Desktop.
Groovy 3.0 YamlBuilder
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.YamlBuilder | |
def counts = [ 1, 2, 3 ] | |
def yaml = new YamlBuilder() | |
yaml(counts) | |
assert yaml.toString() == '''\ | |
--- | |
- 1 | |
- 2 | |
- 3 | |
''' |
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.YamlBuilder | |
def config = [ name: 'orders-api', sidecars: ['cadvisor', 'metricbeat', 'xray'] ] | |
def yaml = new YamlBuilder() | |
yaml(config) | |
assert yaml.toString() == '''\ | |
--- | |
name: "orders-api" | |
sidecars: | |
- "cadvisor" | |
- "metricbeat" | |
- "xray" | |
''' |
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.YamlBuilder | |
class Person { int age; List languages; String name; } | |
def person = new Person(age: 30, name:'Claude', languages: ['English', 'French']) | |
def yaml = new YamlBuilder() | |
yaml(person) | |
assert yaml.toString() == '''\ | |
--- | |
- languages: | |
- "English" | |
- "French" | |
age: 30 | |
name: "Claude" | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment