Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.dataformat.csv

public Class CsvSchema

extends Object
implements FormatSchema, Iterable<CsvSchema.Column>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Iterable, com.fasterxml.jackson.core.FormatSchema
Imports
java.util.*, java.util.function.UnaryOperator, com.fasterxml.jackson.core.FormatSchema

Simple FormatSchema sub-type that defines properties of a CSV document to read or write. Properties supported currently are:

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
CsvSchema.Builder

Class used for building CsvSchema instances.

public static class
CsvSchema.Column

Representation of info for a single column

public static enum
CsvSchema.ColumnType

Enumeration that defines optional type indicators that can be passed with schema.

Field Summary

Modifier and TypeField 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 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.

protected final String
protected final CsvSchema.Column[]
_columns

Column definitions, needed for optional header and/or mapping of field names to column positions.

protected final Map<String, CsvSchema.Column>
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 null is used as marker.

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.Column[]
private static final long

Constructor Summary

AccessConstructor and Description
public
CsvSchema(CsvSchema.Column[] columns, int features, char columnSeparator, int quoteChar, int escapeChar, char[] lineSeparator, String arrayElementSeparator, char[] nullValue, String anyPropertyName)

protected
CsvSchema(CsvSchema.Column[] columns, int features, char columnSeparator, int quoteChar, int escapeChar, char[] lineSeparator, String arrayElementSeparator, char[] nullValue, Map<String, CsvSchema.Column> columnsByName, String anyPropertyName)

Copy constructor used for creating variants using withXxx() methods.

protected
CsvSchema(CsvSchema base, CsvSchema.Column[] columns)

Copy constructor used for creating variants using sortedBy() methods.

protected
CsvSchema(CsvSchema base, int features)

Copy constructor used for creating variants for on/off features

Method Summary

Modifier and TypeMethod and Description
protected static String
protected CsvSchema
_withColumn(int ix, CsvSchema.Column toReplace)

protected CsvSchema
_withFeature(int feature, boolean state)

public boolean
public static CsvSchema.Builder
public CsvSchema.Column
column(int index)

Accessor for column at specified index (0-based); index having to be within

    0 <= index < size()
public CsvSchema.Column
column(String name)

public CsvSchema.Column
column(String name, int probableIndex)

Optimized variant where a hint is given as to likely index of the column name.

public int

Returns:

Index of the specified column, if one exists; -1 if not
columnIndex
(String
Name of column to find
name
)

Method for finding index of a named column within this schema.

public String
columnName(int index)

public static CsvSchema
emptySchema()

Accessor for creating a "default" CSV schema instance, with following settings:

  • Does NOT use header line
  • Uses double quotes ('"') for quoting of field values (if necessary)
  • Uses comma (',') as the field separator
  • Uses Unix linefeed ('\n') as row separator
  • Does NOT use any escape characters
  • Does NOT have any columns defined
public String
public String
public String
getColumnDesc()

Method for getting description of column definitions in developer-readable form

public List<String>
getColumnNames()

Accessor for getting names of included columns, in the order they are included in the schema.

public Collection<String>
getColumnNames(Collection<String> names)

Accessor for getting names of included columns, added in given Collection.

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.
getNullValue
()

public char[]
getNullValueOrEmpty()

Same as getNullValue() except that undefined null value (one that remains as null, or explicitly set as such) will be returned as empty char[]

public String
public int
public String
getSchemaType()

Implements com.fasterxml.jackson.core.FormatSchema.getSchemaType.

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<CsvSchema.Column>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public CsvSchema.Builder
rebuild()

Helper method for constructing Builder that can be used to create modified schema.

public boolean
public int

Returns:

Number of columns this schema defines
size
()

Accessor for finding out how many columns this schema defines.

public boolean
public CsvSchema
sortedBy(String... columnNames)

Mutant factory method that will construct a new instance in which columns are sorted based on names given as argument.

public CsvSchema
sortedBy(Comparator<String> cmp)

Mutant factory method that will construct a new instance in which columns are sorted using given Comparator over column names.

public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

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 constructed CsvSchema with changed column
withColumn
(String
Name of column to replace
columnName
,
UnaryOperator<CsvSchema.Column>
Transformation to apply to the column
transformer
)

Mutant 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 constructed CsvSchema with changed column
withColumn
(int
Index of column to replace
columnIndex
,
UnaryOperator<CsvSchema.Column>
Transformation to apply to the column
transformer
)

Mutant 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.
withColumnReordering
(boolean
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 constructed CsvSchema with appended columns.
withColumnsFrom
(CsvSchema toAppend)

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
withQuoteChar(char c)

public CsvSchema
withSkipFirstDataRow(boolean state)

public CsvSchema

Returns:

A copy of itself, ensuring the setting for the strict headers feature.
withStrictHeaders
(boolean
New value for setting
state
)

Returns a clone of this instance by changing or setting the strict headers flag

public CsvSchema
withUseHeader(boolean state)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait