Package groovy.yaml
Class YamlSlurper
java.lang.Object
groovy.yaml.YamlSlurper
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.
- Since:
- 3.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a YAML parser that produces standard Groovy data structures. -
Method Summary
Modifier and TypeMethodDescriptionReturns how a date-like string is handled when parsing.Parse the content of the specified file into a tree of Nodes.parse(InputStream stream) Parse the content of the specified reader into a tree of Nodes.Parse the content of the specified reader into a tree of Nodes.Parse the content of the specified path into a tree of Nodes.<T> TParse YAML from a file into a typed object.<T> TparseAs(Class<T> type, InputStream stream) Parse YAML from an input stream into a typed object.<T> TParse YAML from a reader into a typed object.<T> TParse YAML from a path into a typed object.Parse the content of the specified yaml into a tree of Nodes.<T> TparseTextAs(Class<T> type, String yaml) Parse the content of the specified YAML text into a typed object using Jackson databinding.setDateHandling(JsonDateHandling dateHandling) Chooses what a string in full ISO-8601 or JSON-date form becomes, matching the date handlingJsonSlurperoffers.
-
Constructor Details
-
YamlSlurper
public YamlSlurper()Creates a YAML parser that produces standard Groovy data structures.
-
-
Method Details
-
getDateHandling
Returns how a date-like string is handled when parsing.- Returns:
- the current date handling,
JsonDateHandling.STRINGby default - Since:
- 6.0.0
- See Also:
-
setDateHandling
Chooses what a string in full ISO-8601 or JSON-date form becomes, matching the date handlingJsonSlurperoffers. The default isJsonDateHandling.STRING: a date-like string is left as aString, which is what this slurper has always produced. A date carrying no time, such as"2026-09-04", is left as aStringwhatever is chosen here.Choosing anything other than
JsonDateHandling.STRINGswitches the underlying parser toJsonParserType.INDEX_OVERLAYso 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. PassnullorJsonDateHandling.STRINGto restore the default parser and string handling.- Parameters:
dateHandling- what a date-like string should become- Returns:
- this slurper, for chaining
- Since:
- 6.0.0
-
parseText
Parse the content of the specified yaml into a tree of Nodes.- Parameters:
yaml- the content of yaml- Returns:
- the root node of the parsed tree of Nodes
-
parse
Parse the content of the specified reader into a tree of Nodes.- Parameters:
reader- the reader of yaml- Returns:
- the root node of the parsed tree of Nodes
-
parse
Parse the content of the specified reader into a tree of Nodes.- Parameters:
stream- the reader of yaml- Returns:
- the root node of the parsed tree of Nodes
-
parse
Parse the content of the specified file into a tree of Nodes.- Parameters:
file- the reader of yaml- Returns:
- the root node of the parsed tree of Nodes
- Throws:
IOException
-
parse
Parse the content of the specified path into a tree of Nodes.- Parameters:
path- the reader of yaml- Returns:
- the root node of the parsed tree of Nodes
- Throws:
IOException
-
parseTextAs
Parse the content of the specified YAML text into a typed object using Jackson databinding. Supports@JsonPropertyand@JsonFormatannotations for property mapping and type conversion.- Type Parameters:
T- the target type- Parameters:
type- the target typeyaml- the content of YAML- Returns:
- a typed object
- Since:
- 6.0.0
-
parseAs
Parse YAML from a reader into a typed object.- Type Parameters:
T- the target type- Parameters:
type- the target typereader- the reader of YAML- Returns:
- a typed object
- Since:
- 6.0.0
-
parseAs
Parse YAML from an input stream into a typed object.- Type Parameters:
T- the target type- Parameters:
type- the target typestream- the input stream of YAML- Returns:
- a typed object
- Since:
- 6.0.0
-
parseAs
Parse YAML from a file into a typed object.- Type Parameters:
T- the target type- Parameters:
type- the target typefile- the YAML file- Returns:
- a typed object
- Throws:
IOException- Since:
- 6.0.0
-
parseAs
Parse YAML from a path into a typed object.- Type Parameters:
T- the target type- Parameters:
type- the target typepath- the path to the YAML file- Returns:
- a typed object
- Throws:
IOException- Since:
- 6.0.0
-