Class TOML


  • public final class TOML
    extends Object
    TOML is the result from parsing a TOML file. This class includes some methods for querying the generated object-tree, for more advanced querying consider using a specific object-tree querying library such as OGNL, Apache Commons EL, etc.
    • Method Detail

      • getErrors

        public List<String> getErrors()
        Returns a list of the syntax errors generated during parsing.
        Returns:
        A list of errors generated during parsing.
      • getRoot

        public Map<String,​Object> getRoot()
        Returns the root table representing the document.
        Returns:
        The root table representing the parsed TOML document.
      • subtree

        public TOML subtree​(String prefix)
        Returns a new TOML subtree given a prefix.
        Parameters:
        prefix - The prefix.
        Returns:
        A TOML object to query the subtree.
      • toString

        public String toString()
        Prints out the object tree. For debugging purposes.
        Overrides:
        toString in class Object
        Returns:
        A String representation of the object tree.
      • getString

        public Optional<String> getString​(String path)
        Retrieves a String value from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The String value, if any, or Optional.empty() otherwise.
      • getLong

        public Optional<Long> getLong​(String path)
        Retrieves a Long value from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The Long value, if any, or Optional.empty() otherwise.
      • getDouble

        public Optional<Double> getDouble​(String path)
        Retrieves a Double value from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The Double value, if any, or Optional.empty() otherwise.
      • getArray

        public Optional<List> getArray​(String path)
        Retrieves a List value from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The List value, if any, or Optional.empty() otherwise.
      • getBoolean

        public Optional<Boolean> getBoolean​(String path)
        Retrieves a Boolean value from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The Boolean value, if any, or Optional.empty() otherwise.
      • getInstant

        public Optional<Instant> getInstant​(String path)
        Retrieves a Instant value from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The Instant value, if any, or Optional.empty() otherwise.
      • getOffsetDateTime

        public Optional<OffsetDateTime> getOffsetDateTime​(String path)
        Retrieves a OffsetDateTime value from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The OffsetDateTime value, if any, or Optional.empty() otherwise.
      • getLocalDateTime

        public Optional<LocalDateTime> getLocalDateTime​(String path)
        Retrieves a LocalDateTime value from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The LocalDateTime value, if any, or Optional.empty() otherwise.
      • getLocalDate

        public Optional<LocalDate> getLocalDate​(String path)
        Retrieves a LocalDate value from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The LocalDate value, if any, or Optional.empty() otherwise.
      • getLocalTime

        public Optional<LocalTime> getLocalTime​(String path)
        Retrieves a LocalTime value from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The LocalTime value, if any, or Optional.empty() otherwise.
      • getTable

        public Optional<Map<String,​Object>> getTable​(String path)
        Retrieves a table from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The Map stored in the given path, or Optional.empty() otherwise.
      • getTableArray

        public Optional<List<Map<String,​Object>>> getTableArray​(String path)
        Retrieves a list of tables from this TOML object.
        Parameters:
        path - The path, separated by forward slashes, as in "a/b/c"
        Returns:
        The List of tables, if any, or Optional.empty() otherwise.
      • writeJSON

        public void writeJSON​(Writer out)
                       throws IOException
        Utility method to write a JSON representation of the Java object tree.
        Parameters:
        out - The Writer where the JSON representation is expected.
        Throws:
        IOException - If an I/O error happens.
      • writeJSON

        public void writeJSON​(PrintStream out)
                       throws IOException
        Utility method to write a JSON representation of the Java object tree.
        Parameters:
        out - The Writer where the JSON representation is expected.
        Throws:
        IOException - If an I/O error happens.