|
8 | 8 |
|
9 | 9 | Library to easily use *Kotlin Serialization* to serialize/parse CSV. |
10 | 10 |
|
| 11 | +All types of record classes are supported (primitives, classes, enums, nested classes, ...). |
| 12 | +However, CSV serialization works best if the column number if fixed. So, collections (lists, sets, maps) and |
| 13 | +open classes should be avoided. |
| 14 | + |
11 | 15 | ## Gradle Dependencies |
12 | 16 | ```kotlin |
13 | 17 | // Kotlin Serialization CSV |
@@ -60,6 +64,32 @@ fun main() { |
60 | 64 | } |
61 | 65 | ``` |
62 | 66 |
|
| 67 | +### Pre-defined CSV formats |
| 68 | +The library comes with multiple pre-defined formats that can be used out of the box. |
| 69 | + |
| 70 | +| Config | Description | |
| 71 | +|--- |--- | |
| 72 | +| `default` | Standard Comma Separated Value format, as for `rfc4180` but allowing empty lines. *Format is unstable and may change in upcoming versions.* | |
| 73 | +| `rfc4180` | Comma separated format as defined by [RFC 4180](http://tools.ietf.org/html/rfc4180). | |
| 74 | +| `excel` | Excel file format (using a comma as the value delimiter). | |
| 75 | + |
| 76 | +### Configuration |
| 77 | +CSV serialization and parsing options can be changed by providing a custom `CsvConfiguration`. |
| 78 | + |
| 79 | +| Option | Default Value | Description | |
| 80 | +|--- |--- | --- | |
| 81 | +| `delimiter` | `,` | The delimiter character between columns. | |
| 82 | +| `recordSeparator` | `\r\n` | The record separator. | |
| 83 | +| `quoteChar` | `"` | The quote character used to quote column values. | |
| 84 | +| `quoteMode` | `MINIMAL` | The quote mode used to decide if a column value should get quoted.<ul><li>`ALL`: Quotes *all* fields.</li><li>`ALL_NON_NULL`: Quotes all *non-null fields* and *fields which contain special characters*.</li><li>`ALL_NON_NUMERIC`: Quotes all *non-numeric fields* and *fields which contain special characters*.</li><li>`MINIMAL`: Quotes *fields which contain special characters*.</li><li>`NONE`: *Never* quotes fields (requires `CsvConfiguration.escapeChar` to be set).</li></ul> | |
| 85 | +| `escapeChar` | `null` (`\\` for `QuoteMode.NONE`) | The escape character used to escape reserved characters in a column value. | |
| 86 | +| `nullString` | *empty string* | The value to identify `null` values. | |
| 87 | +| `unitString` | `Unit` | The value to identify `Unit` values. | |
| 88 | +| `ignoreEmptyLines` | `true` | Ignore empty lines during parsing. | |
| 89 | +| `hasHeaderRecord` | `false` | First line is header record. | |
| 90 | +| `headerSeparator` | `.` | Character that is used to separate hierarchical header names. | |
| 91 | +| `hasTrailingDelimiter` | `false` | If records end with a trailing `delimiter`. | |
| 92 | + |
63 | 93 | ## Requirements |
64 | 94 |
|
65 | 95 | | Dependency | Versions | |
|
0 commit comments