Package: groovy.csv

## [Java] Class CsvSlurper

- groovy.csv.CsvSlurper

-     @Incubating
      public class CsvSlurper
      extends Object

  Represents a CSV parser.

  Usage:

       def csv = new groovy.csv.CsvSlurper().parseText('name,age\nAlice,30\nBob,25')
       assert csv[0].name == 'Alice'
       assert csv[1].age == '25'

  Since:
    6.0.0

- - ### Constructor Summary

    Constructors
    Constructor and description
    `CsvSlurper()` Creates a slurper that uses comma-separated columns, double quotes, and treats the first row as headers.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public List<Map<String, String>>` | `parse(Reader reader)` Parse CSV from a reader.
    `` | `public List<Map<String, String>>` | `parse(InputStream stream)` Parse CSV from an input stream.
    `` | `public List<Map<String, String>>` | `parse(File file)` Parse CSV from a file.
    `` | `public List<Map<String, String>>` | `parse(Path path)` Parse CSV from a path.
    `<T>` | `public List<T>` | `parseAs(Class<T> type, String csv)` Parse CSV into typed objects using Jackson databinding.
    `<T>` | `public List<T>` | `parseAs(Class<T> type, Reader reader)` Parse CSV from a reader into typed objects.
    `<T>` | `public List<T>` | `parseAs(Class<T> type, File file)` Parse CSV from a file into typed objects.
    `<T>` | `public List<T>` | `parseAs(Class<T> type, Path path)` Parse CSV from a path into typed objects.
    `` | `public List<Map<String, String>>` | `parseText(String csv)` Parse the content of the specified CSV text.
    `` | `public CsvSlurper` | `setQuoteChar(char quoteChar)` Set the quote character (default: double-quote).
    `` | `public CsvSlurper` | `setSeparator(char separator)` Set the column separator character (default: comma).
    `` | `public CsvSlurper` | `setUseHeader(boolean useHeader)` Set whether the first row is a header row (default: true).

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### public CsvSlurper()

      Creates a slurper that uses comma-separated columns, double quotes, and treats the first row as headers.

  - ### Method Detail

    - #### public List<Map<String, String>> parse(Reader reader)

      Parse CSV from a reader. When `useHeader` is true (the default), each row is returned as a map keyed by column headers from the first row. When `useHeader` is false, maps are keyed by auto-generated column names.

      Parameters:
        `reader` - the reader of CSV
      Returns:
        a list of maps (one per row)

    - #### public List<Map<String, String>> parse(InputStream stream)

      Parse CSV from an input stream. The caller is responsible for closing the stream.

      Parameters:
        `stream` - the input stream of CSV
      Returns:
        a list of maps (one per row)

    - #### public List<Map<String, String>> parse(File file)

      Parse CSV from a file.

      Parameters:
        `file` - the CSV file
      Returns:
        a list of maps (one per row), keyed by column headers

    - #### public List<Map<String, String>> parse(Path path)

      Parse CSV from a path.

      Parameters:
        `path` - the path to the CSV file
      Returns:
        a list of maps (one per row), keyed by column headers

    - #### <T> public List<T> parseAs(Class<T> type, String csv)

      Parse CSV into typed objects using Jackson databinding. Supports `@JsonProperty` and `@JsonFormat` annotations for column mapping and type conversion.

      Parameters:
        `type` - the target type
        `csv` - the CSV text
      Type Parameters:
        `T` - the target type
      Returns:
        a list of typed objects

    - #### <T> public List<T> parseAs(Class<T> type, Reader reader)

      Parse CSV from a reader into typed objects.

      Parameters:
        `type` - the target type
        `reader` - the reader of CSV
      Type Parameters:
        `T` - the target type
      Returns:
        a list of typed objects

    - #### <T> public List<T> parseAs(Class<T> type, File file)

      Parse CSV from a file into typed objects.

      Parameters:
        `type` - the target type
        `file` - the CSV file
      Type Parameters:
        `T` - the target type
      Returns:
        a list of typed objects

    - #### <T> public List<T> parseAs(Class<T> type, Path path)

      Parse CSV from a path into typed objects.

      Parameters:
        `type` - the target type
        `path` - the path to the CSV file
      Type Parameters:
        `T` - the target type
      Returns:
        a list of typed objects

    - #### public List<Map<String, String>> parseText(String csv)

      Parse the content of the specified CSV text.

      Parameters:
        `csv` - the CSV text
      Returns:
        a list of maps (one per row), keyed by column headers

    - #### public CsvSlurper setQuoteChar(char quoteChar)

      Set the quote character (default: double-quote).

      Parameters:
        `quoteChar` - the quote character
      Returns:
        this slurper for chaining

    - #### public CsvSlurper setSeparator(char separator)

      Set the column separator character (default: comma).

      Parameters:
        `separator` - the separator character
      Returns:
        this slurper for chaining

    - #### public CsvSlurper setUseHeader(boolean useHeader)

      Set whether the first row is a header row (default: true).

      Parameters:
        `useHeader` - true to treat the first row as headers
      Returns:
        this slurper for chaining