@Incubating
public class CsvBuilder
extends Object
implements Writable
Builds CSV output from collections of maps or typed objects.
Example with maps:
def data = [[name: 'Alice', age: 30], [name: 'Bob', age: 25]]
def csv = groovy.csv.CsvBuilder.toCsv(data)
assert csv.contains('name,age')
assert csv.contains('Alice,30')
| Constructor and description |
|---|
CsvBuilder() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public CsvBuilder |
call(Collection<? extends Map<String, ?>> data)Build CSV from a collection of maps. |
|
public CsvBuilder |
setQuoteChar(char quoteChar)Set the quote character (default: double-quote). |
|
public CsvBuilder |
setSeparator(char separator)Set the column separator character (default: comma). |
|
public static String |
toCsv(Collection<? extends Map<String, ?>> data)Convert a collection of maps to CSV. |
<T> |
public static String |
toCsv(Collection<T> data, Class<T> type)Convert a collection of typed objects to CSV using Jackson databinding. |
|
public String |
toString() |
|
public Writer |
writeTo(Writer out) |
Build CSV from a collection of maps.
data - the collection of mapsSet the quote character (default: double-quote).
quoteChar - the quote characterSet the column separator character (default: comma).
separator - the separator characterConvert a collection of maps to CSV. The keys of the first map are used as column headers.
data - the collection of maps Convert a collection of typed objects to CSV using Jackson databinding.
Supports @JsonProperty and @JsonFormat annotations.
data - the collection of objectstype - the object type (used to derive the schema)T - the object typeCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.