YAML support for Apache Groovy providing parsing, building, and conversion capabilities
npx @tessl/cli install tessl/maven-org-apache-groovy--groovy-yaml@5.0.0Groovy YAML provides comprehensive YAML processing capabilities for the Apache Groovy programming language. It includes YamlSlurper for parsing YAML documents into Groovy data structures, YamlBuilder for programmatically constructing YAML documents using Groovy's builder pattern, and utility classes for converting between YAML and JSON formats.
Gradle:
implementation 'org.apache.groovy:groovy-yaml:5.0.0'Maven:
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-yaml</artifactId>
<version>5.0.0</version>
</dependency>import groovy.yaml.YamlSlurper;
import groovy.yaml.YamlBuilder;
import groovy.yaml.YamlRuntimeException;
import org.apache.groovy.yaml.util.YamlConverter;import groovy.yaml.YamlSlurper;
import groovy.yaml.YamlBuilder;
// Parse YAML content
YamlSlurper yamlSlurper = new YamlSlurper();
Object result = yamlSlurper.parseText("""
language: groovy
version: 5.0.0
features:
- yaml-parsing
- yaml-building
""");
// Build YAML content
YamlBuilder yamlBuilder = new YamlBuilder();
yamlBuilder.call(Map.of(
"language", "groovy",
"version", "5.0.0",
"features", List.of("yaml-parsing", "yaml-building")
));
String yamlOutput = yamlBuilder.toString();Groovy YAML is built around several key components:
Parse YAML documents from various sources (strings, streams, files) into Groovy data structures that can be accessed using Groovy's dynamic syntax.
public class YamlSlurper {
public YamlSlurper();
public Object parseText(String yaml);
public Object parse(Reader reader);
public Object parse(InputStream stream);
public Object parse(java.io.File file) throws IOException;
public Object parse(Path path) throws IOException;
}Programmatically construct YAML documents using Groovy's builder pattern with support for closures, maps, lists, and dynamic method calls.
public class YamlBuilder extends GroovyObjectSupport implements Writable {
public YamlBuilder();
public Object getContent();
public Object call(Map m);
public Object call(List l);
public Object call(Object... args);
public Object call(Iterable coll, Closure c);
public Object call(Collection coll, Closure c);
public Object call(Closure c);
public Object invokeMethod(String name, Object args);
public String toString();
public Writer writeTo(Writer out) throws IOException;
}Convert between YAML and JSON formats using utility methods that leverage Jackson's processing capabilities.
public final class YamlConverter {
public static String convertYamlToJson(Reader yamlReader);
public static String convertJsonToYaml(Reader jsonReader);
}public class YamlRuntimeException extends GroovyRuntimeException {
public YamlRuntimeException(String msg);
public YamlRuntimeException(Throwable cause);
public YamlRuntimeException(String msg, Throwable cause);
}