Package groovy.toml

Class TomlSlurper

java.lang.Object
groovy.toml.TomlSlurper

@Incubating public class TomlSlurper extends Object
Represents a TOML parser
Since:
4.0.0
  • Constructor Details

    • TomlSlurper

      public TomlSlurper()
      Creates a TOML parser that produces standard Groovy data structures.
  • Method Details

    • getDateHandling

      public JsonDateHandling getDateHandling()
      Returns how a date-like string is handled when parsing.
      Returns:
      the current date handling, JsonDateHandling.STRING by default
      Since:
      6.0.0
      See Also:
    • setDateHandling

      public TomlSlurper setDateHandling(JsonDateHandling dateHandling)
      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.

      Parameters:
      dateHandling - what a date-like string should become
      Returns:
      this slurper, for chaining
      Since:
      6.0.0
    • parseText

      public Object parseText(String toml)
      Parse the content of the specified toml into a tree of Nodes.
      Parameters:
      toml - the content of toml
      Returns:
      the root node of the parsed tree of Nodes
    • parse

      public Object parse(Reader reader)
      Parse the content of the specified reader into a tree of Nodes.
      Parameters:
      reader - the reader of toml
      Returns:
      the root node of the parsed tree of Nodes
    • parse

      public Object parse(InputStream stream)
      Parse the content of the specified reader into a tree of Nodes.
      Parameters:
      stream - the reader of toml
      Returns:
      the root node of the parsed tree of Nodes
    • parse

      public Object parse(File file) throws IOException
      Parse the content of the specified file into a tree of Nodes.
      Parameters:
      file - the reader of toml
      Returns:
      the root node of the parsed tree of Nodes
      Throws:
      IOException
    • parse

      public Object parse(Path path) throws IOException
      Parse the content of the specified path into a tree of Nodes.
      Parameters:
      path - the reader of toml
      Returns:
      the root node of the parsed tree of Nodes
      Throws:
      IOException
    • parseTextAs

      public <T> T parseTextAs(Class<T> type, String toml)
      Parse the content of the specified TOML text into a typed object using Jackson databinding. Supports @JsonProperty and @JsonFormat annotations for property mapping and type conversion.
      Type Parameters:
      T - the target type
      Parameters:
      type - the target type
      toml - the content of TOML
      Returns:
      a typed object
      Since:
      6.0.0
    • parseAs

      public <T> T parseAs(Class<T> type, Reader reader)
      Parse TOML from a reader into a typed object.
      Type Parameters:
      T - the target type
      Parameters:
      type - the target type
      reader - the reader of TOML
      Returns:
      a typed object
      Since:
      6.0.0
    • parseAs

      public <T> T parseAs(Class<T> type, InputStream stream)
      Parse TOML from an input stream into a typed object.
      Type Parameters:
      T - the target type
      Parameters:
      type - the target type
      stream - the input stream of TOML
      Returns:
      a typed object
      Since:
      6.0.0
    • parseAs

      public <T> T parseAs(Class<T> type, File file) throws IOException
      Parse TOML from a file into a typed object.
      Type Parameters:
      T - the target type
      Parameters:
      type - the target type
      file - the TOML file
      Returns:
      a typed object
      Throws:
      IOException
      Since:
      6.0.0
    • parseAs

      public <T> T parseAs(Class<T> type, Path path) throws IOException
      Parse TOML from a path into a typed object.
      Type Parameters:
      T - the target type
      Parameters:
      type - the target type
      path - the path to the TOML file
      Returns:
      a typed object
      Throws:
      IOException
      Since:
      6.0.0