Skip to content

Instantly share code, notes, and snippets.

@kirklewis
Created February 16, 2020 19:09
Show Gist options
  • Save kirklewis/e7dd2f9402679c4c36d4132d4f28b2ee to your computer and use it in GitHub Desktop.
Save kirklewis/e7dd2f9402679c4c36d4132d4f28b2ee to your computer and use it in GitHub Desktop.
Groovy 3.0 YamlBuilder
import groovy.yaml.YamlBuilder
def counts = [ 1, 2, 3 ]
def yaml = new YamlBuilder()
yaml(counts)
assert yaml.toString() == '''\
---
- 1
- 2
- 3
'''
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"
'''
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