Last active
July 5, 2024 18:24
-
-
Save Joxebus/6ba83b3aab0c5498daf990b9ede10b19 to your computer and use it in GitHub Desktop.
YAML sample with Groovy 3
This file contains hidden or 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 slurper = new YamlSlurper() | |
def configuration = ''' | |
version: 3.0 | |
environment: "dev" | |
context: | |
path: "/test" | |
endpoints: | |
url: "/people" | |
operations: | |
POST: "create" | |
GET: "list or get" | |
PUT: "/update" | |
DELETE: "delete" | |
''' | |
def yaml = slurper.parseText(configuration) | |
println "YAML keys: ${yaml.keySet()}" | |
yaml.keySet().each { key -> | |
println "Key: $key \t Type: ${yaml[key].getClass().name}" | |
} |
This file contains hidden or 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 yaml = new YamlBuilder() | |
yaml { | |
version 3.0 | |
environment "dev" | |
context { | |
path "/test" | |
} | |
endpoints { | |
url "/people" | |
operations ("POST":"create", "GET":"list or get", "PUT":"update", "DELETE":"delete") | |
} | |
} | |
println yaml |
This file contains hidden or 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 | |
Map configuration = [ | |
version : 3.0, | |
environment : "dev", | |
context : [path:"/test"], | |
endpoints : [url:"/people", | |
operations: [POST:"create", GET:"list or get", | |
PUT:"update", DELETE:"delete"] | |
] | |
] | |
def yaml = new YamlBuilder() | |
yaml(configuration) | |
println yaml |
This file contains hidden or 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 Configuration { | |
BigDecimal version | |
String environment | |
Map context | |
Map endpoints | |
} | |
def configuration = new Configuration() | |
configuration.with{ | |
version = 3.0 | |
environment = "dev" | |
context = [path:"/test"] | |
endpoints = [url:"/people", | |
operations: [POST:"create", GET:"list or get", | |
PUT:"update", DELETE:"delete"] | |
] | |
} | |
def yaml = new YamlBuilder() | |
yaml(configuration) | |
println yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment