public class YamlSlurper
extends Object
Represents a YAML parser
YAML anchors and aliases are not resolved: an alias is returned as a plain string
holding the anchor's name, and a merge key (<<) is left as a literal entry.
This comes from the Jackson YAML backend and is a deliberate limitation there. The
Processing YAML user guide covers it, along with what to use when a document relies
on anchors.
| Constructor and description |
|---|
YamlSlurper()Creates a YAML parser that produces standard Groovy data structures. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public JsonDateHandling |
getDateHandling()Returns how a date-like string is handled when parsing. |
|
public Object |
parse(Reader reader)Parse the content of the specified reader into a tree of Nodes. |
|
public Object |
parse(InputStream stream)Parse the content of the specified reader into a tree of Nodes. |
|
public Object |
parse(File file)Parse the content of the specified file into a tree of Nodes. |
|
public Object |
parse(Path path)Parse the content of the specified path into a tree of Nodes. |
<T> |
public T |
parseAs(Class<T> type, Reader reader)Parse YAML from a reader into a typed object. |
<T> |
public T |
parseAs(Class<T> type, InputStream stream)Parse YAML from an input stream into a typed object. |
<T> |
public T |
parseAs(Class<T> type, File file)Parse YAML from a file into a typed object. |
<T> |
public T |
parseAs(Class<T> type, Path path)Parse YAML from a path into a typed object. |
|
public Object |
parseText(String yaml)Parse the content of the specified yaml into a tree of Nodes. |
<T> |
public T |
parseTextAs(Class<T> type, String yaml)Parse the content of the specified YAML text into a typed object using Jackson databinding. |
|
public YamlSlurper |
setDateHandling(JsonDateHandling dateHandling)Chooses what a string in full ISO-8601 or JSON-date form becomes, matching the date handling JsonSlurper offers. |
Creates a YAML parser that produces standard Groovy data structures.
Returns how a date-like string is handled when parsing.
Parse the content of the specified reader into a tree of Nodes.
reader - the reader of yamlParse the content of the specified reader into a tree of Nodes.
stream - the reader of yamlParse the content of the specified file into a tree of Nodes.
file - the reader of yamlParse the content of the specified path into a tree of Nodes.
path - the reader of yamlParse YAML from a reader into a typed object.
type - the target typereader - the reader of YAMLT - the target typeParse YAML from an input stream into a typed object.
type - the target typestream - the input stream of YAMLT - the target typeParse YAML from a file into a typed object.
type - the target typefile - the YAML fileT - the target typeParse YAML from a path into a typed object.
type - the target typepath - the path to the YAML fileT - the target typeParse the content of the specified yaml into a tree of Nodes.
yaml - the content of yaml Parse the content of the specified YAML text into a typed object using Jackson databinding.
Supports @JsonProperty and @JsonFormat annotations for
property mapping and type conversion.
type - the target typeyaml - the content of YAMLT - the target type Chooses what a string in full ISO-8601 or JSON-date form becomes, matching the
date handling JsonSlurper offers. The default is JsonDateHandling.STRING:
a date-like string is left as a String, which is what this slurper has always
produced. A date carrying no time, such as "2026-09-04", is left as a
String whatever is chosen here.
Choosing anything other than JsonDateHandling.STRING switches the underlying
parser to JsonParserType.INDEX_OVERLAY so the conversion takes effect; as a
consequence, the iteration order of a map with more than a handful of entries is no
longer the document order. Pass null or JsonDateHandling.STRING to
restore the default parser and string handling.
dateHandling - what a date-like string should becomeCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.