or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

format-conversion.mdindex.mdyaml-building.mdyaml-parsing.md
tile.json

tessl/maven-org-apache-groovy--groovy-yaml

YAML support for Apache Groovy providing parsing, building, and conversion capabilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.apache.groovy/groovy-yaml@5.0.x

To install, run

npx @tessl/cli install tessl/maven-org-apache-groovy--groovy-yaml@5.0.0

index.mddocs/

Groovy YAML

Groovy 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.

Package Information

  • Package Name: org.apache.groovy:groovy-yaml
  • Package Type: maven
  • Language: Java/Groovy
  • Installation: Add to your build.gradle or pom.xml:

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>

Core Imports

import groovy.yaml.YamlSlurper;
import groovy.yaml.YamlBuilder;
import groovy.yaml.YamlRuntimeException;
import org.apache.groovy.yaml.util.YamlConverter;

Basic Usage

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();

Architecture

Groovy YAML is built around several key components:

  • YamlSlurper: YAML parser that converts YAML documents into Groovy data structures, similar to JsonSlurper
  • YamlBuilder: YAML builder using Groovy's builder pattern with closure support for programmatic YAML construction
  • YamlConverter: Utility for bidirectional YAML/JSON conversion leveraging Jackson libraries
  • YamlRuntimeException: Specialized exception handling for YAML processing errors
  • Integration Layer: Seamless integration with Groovy's dynamic features and existing JSON processing APIs

Capabilities

YAML Parsing

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;
}

YAML Parsing

YAML Building

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;
}

YAML Building

Format Conversion

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);
}

Format Conversion

Types

public class YamlRuntimeException extends GroovyRuntimeException {
    public YamlRuntimeException(String msg);
    public YamlRuntimeException(Throwable cause);
    public YamlRuntimeException(String msg, Throwable cause);
}