FormatSchema sub-type that defines properties of
a CSV document to read or write.
Properties supported currently are:
columns (List of ColumnDef) [default: empty List]: Ordered list of columns (which may be empty, see below).
Each column has name (mandatory) as well as type (optional; if not
defined, defaults to "String").
Note that
useHeader (boolean) [default: false]: whether the first line of physical document defines
column names (true) or not (false): if enabled, parser will take
first-line values to define column names; and generator will output
column names as the first line
quoteChar (char) [default: double-quote ('")]: character used for quoting values
that contain quote characters or linefeeds.
columnSeparator (char) [default: comma (',')]: character used to separate values.
Other commonly used values include tab ('\t') and pipe ('|')
arrayElementSeparator (String) [default: semicolon (";")]: string used to separate array elements.
lineSeparator (String) [default: "\n"]: character used to separate data rows.
Only used by generator; parser accepts three standard linefeeds ("\r", "\r\n", "\n").
escapeChar (int) [default: -1 meaning "none"]: character, if any, used to
escape values. Most commonly defined as backslash ('\'). Only used by parser;
generator only uses quoting, including doubling up of quotes to indicate quote char
itself.
skipFirstDataRow (boolean) [default: false]: whether the first data line (either
first line of the document, if useHeader=false, or second, if useHeader=true)
should be completely ignored by parser. Needed to support CSV-like file formats
that include additional non-data content before real data begins (specifically
some database dumps do this)
nullValue (String) [default: "" (empty String)]: When asked to write Java `null`,
this String value will be used instead.strictHeaders (boolean) [default: false] (added in Jackson 2.7): whether names of
columns defined in the schema MUST match with actual declaration from
the header row (if header row handling enabled): if true, they must be and
an exception if thrown if order differs: if false, no verification is performed.
allowComments (boolean) [default: false]: whether lines that start with character "#"
are processed as comment lines and skipped/ignored.
anyProperty (String] [default: none]: if "any properties" (properties for
'extra' columns; ones not specified in schema) are enabled, they are mapped to
this name: leaving it as null disables use of
"any properties" (and they are either ignored, or an exception
is thrown, depending on other settings); setting it to a non-null
String value will expose all extra properties under one specified name.
Most often used with Jackson @JsonAnySetter annotation.
Note that schemas without any columns are legal, but if no columns are added, behavior of parser/generator is usually different and content will be exposed as logical Arrays instead of Objects.
There are 4 ways to create CsvSchema instances:
Builder
withXxx methods
or rebuild for creating Builder)
CsvMapper methods like CsvMapper#schemaFor(java.lang.Class) .
CsvParser reads schema from the first line:
enable "useHeader" property for the initial schema, and let parser
read column names from the document itself.
| Modifier and Type | Class and Description |
|---|---|
| public static class | CsvSchema.
Class used for building |
| public static class | CsvSchema.
Representation of info for a single column |
| public static enum | CsvSchema.
Enumeration that defines optional type indicators that can be passed with schema. |
| Modifier and Type | Field and Description |
|---|---|
| protected final String | _anyPropertyName
If "any properties" (properties for 'extra' columns; ones
not specified in schema) are enabled, they are mapped to
this name: leaving it as |
| protected final String | |
| protected final CsvSchema. | _columns
Column definitions, needed for optional header and/or mapping of field names to column positions. |
| protected final Map | |
| protected final char | |
| protected final int | |
| protected int | _features
Bitflag for general-purpose on/off features. |
| protected final char[] | |
| protected final char[] | |
| protected transient String | |
| protected final int | |
| public static final String | DEFAULT_ANY_PROPERTY_NAME
By default no "any properties" (properties for 'extra' columns; ones
not specified in schema) are used, so |
| public static final String | DEFAULT_ARRAY_ELEMENT_SEPARATOR
Default separator for array elements within a column value is semicolon. |
| public static final char | DEFAULT_COLUMN_SEPARATOR
Default separator for column values is comma (hence "Comma-Separated Values") |
| protected static final int | |
| public static final int | DEFAULT_ESCAPE_CHAR
By default, no escape character is used -- this is denoted by int value that does not map to a valid character |
| public static final char[] | |
| public static final char[] | DEFAULT_NULL_VALUE
By default, nulls are written as empty Strings (""); and no coercion is performed from any String (higher level databind may, however, coerce Strings into Java nulls). |
| public static final char | |
| protected static final int | |
| protected static final int | |
| protected static final int | |
| protected static final int | |
| protected static final int | |
| public static final String | NO_ARRAY_ELEMENT_SEPARATOR
Marker for the case where no array element separator is used |
| protected static final char[] | |
| protected static final CsvSchema. | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | |
| protected | CsvSchema(CsvSchema.
Copy constructor used for creating variants using
|
| protected | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| private static CsvSchema. | |
| protected static String | |
| protected CsvSchema | |
| protected CsvSchema | |
| public boolean | |
| public static CsvSchema. | |
| public CsvSchema. | column(int index)
Accessor for column at specified index (0-based); index having to be within
0 <= index < size()
|
| public CsvSchema. | |
| public CsvSchema. | |
| public int | Returns: Index of the specified column, if one exists;-1 if notName of column to find name)Method for finding index of a named column within this schema. |
| public String | |
| public static CsvSchema | emptySchema()
Accessor for creating a "default" CSV schema instance, with following settings:
|
| public String | |
| public String | |
| public String | |
| public List | getColumnNames()
Accessor for getting names of included columns, in the order they are included in the schema. |
| public Collection | getColumnNames(Collection<String> names)
Accessor for getting names of included columns, added in given
|
| public char | |
| public int | |
| public char[] | |
| public char[] | Returns: Null value defined, as char array, if one is defined to be recognized; Java null if not.
|
| public char[] | getNullValueOrEmpty()
Same as |
| public String | |
| public int | |
| public String | getSchemaType()
Implements com. Method that can be used to get an identifier that can be used for diagnostics purposes, to indicate what kind of data format this schema is used for: typically it is a short name of format itself, but it can also contain additional information in cases where data format supports multiple types of schemas. |
| public boolean | |
| public Iterator | |
| public CsvSchema. | |
| public boolean | |
| public int | Returns: Number of columns this schema definesAccessor for finding out how many columns this schema defines. |
| public boolean | |
| public CsvSchema | |
| public CsvSchema | sortedBy(Comparator<String> cmp)
Mutant factory method that will construct a new instance in which columns
are sorted using given |
| public boolean | |
| public String | |
| public boolean | |
| public boolean | |
| public boolean | |
| public CsvSchema | withAllowComments(boolean state)
Method to indicate whether "hash comments" are allowed for document described by this schema. |
| public CsvSchema | |
| public CsvSchema | |
| public CsvSchema | Returns: Either this schema (if column did not change), or newly constructedCsvSchema
with changed columnName of column to replace columnName, UnaryOperator<CsvSchema.Transformation to apply to the column transformerMutant factory method that will try to replace specified column with changed definition (but same name), leaving other columns as-is. |
| public CsvSchema | Returns: Either this schema (if column did not change), or newly constructedCsvSchema
with changed columnIndex of column to replace columnIndex, UnaryOperator<CsvSchema.Transformation to apply to the column transformerMutant factory method that will try to replace specified column with changed definition (but same name), leaving other columns as-is. |
| public CsvSchema | Returns: A copy of itself, ensuring the setting for the column reordering feature.New value for setting state)Returns a clone of this instance by changing or setting the column reordering flag |
| public CsvSchema | |
| public CsvSchema | Returns: Either this schema (if nothing changed), or newly constructedCsvSchema
with appended columns.Mutant factory method that will try to combine columns of this schema with those from `toAppend`, starting with columns of this instance, and ignoring duplicates (if any) from argument `toAppend`. |
| public CsvSchema | withComments()
Method to indicate that "hash comments" ARE allowed for document described by this schema. |
| public CsvSchema | |
| public CsvSchema | withHeader()
Helper method for constructing and returning schema instance that is similar to this one, except that it will be using header line. |
| public CsvSchema | |
| public CsvSchema | |
| public CsvSchema | |
| public CsvSchema | |
| public CsvSchema | withoutComments()
Method to indicate that "hash comments" are NOT allowed for document described by this schema. |
| public CsvSchema | |
| public CsvSchema | withoutHeader()
Helper method for construcing and returning schema instance that is similar to this one, except that it will not be using header line. |
| public CsvSchema | |
| public CsvSchema | |
| public CsvSchema | |
| public CsvSchema | Returns: A copy of itself, ensuring the setting for the strict headers feature.New value for setting state)Returns a clone of this instance by changing or setting the strict headers flag |
| public CsvSchema |