Class CsvSchema.Builder

java.lang.Object
com.fasterxml.jackson.dataformat.csv.CsvSchema.Builder
Enclosing class:
CsvSchema

public static class CsvSchema.Builder extends Object
Class used for building CsvSchema instances.
  • Field Details

    • _columns

      protected final ArrayList<CsvSchema.Column> _columns
    • _encodingFeatures

      protected int _encodingFeatures
      Bit-flag for general-purpose on/off features.
      Since:
      2.5
    • _columnSeparator

      protected char _columnSeparator
    • _arrayElementSeparator

      protected String _arrayElementSeparator
    • _anyPropertyName

      protected 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.
      Since:
      2.7
    • _quoteChar

      protected int _quoteChar
    • _escapeChar

      protected int _escapeChar
    • _lineSeparator

      protected char[] _lineSeparator
    • _nullValue

      protected char[] _nullValue
      Since:
      2.5
  • Constructor Details

    • Builder

      public Builder()
    • Builder

      public Builder(CsvSchema src)
      "Copy" constructor which creates builder that has settings of given source schema
  • Method Details

    • addColumn

      public CsvSchema.Builder addColumn(String name)
      NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
    • addColumn

      public CsvSchema.Builder addColumn(String name, CsvSchema.ColumnType type)
      NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
    • addColumn

      public CsvSchema.Builder addColumn(CsvSchema.Column c)
      NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
    • addColumns

      public CsvSchema.Builder addColumns(Iterable<CsvSchema.Column> cs)
      NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
      Since:
      2.9
    • addColumns

      public CsvSchema.Builder addColumns(Iterable<String> names, CsvSchema.ColumnType type)
      NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
      Since:
      2.9
    • addColumnsFrom

      public CsvSchema.Builder addColumnsFrom(CsvSchema schema)
      NOTE: unlike many other add methods, this method DOES check for, and discard, possible duplicate columns: that is, if this builder already has a column with same name as column to be added, existing column is retained and new column ignored.
      Since:
      2.9
    • addArrayColumn

      public CsvSchema.Builder addArrayColumn(String name)
    • addArrayColumn

      public CsvSchema.Builder addArrayColumn(String name, String elementSeparator)
      Since:
      2.7
    • addNumberColumn

      public CsvSchema.Builder addNumberColumn(String name)
    • addBooleanColumn

      public CsvSchema.Builder addBooleanColumn(String name)
    • renameColumn

      public CsvSchema.Builder renameColumn(int index, String newName)
    • replaceColumn

      public CsvSchema.Builder replaceColumn(int index, CsvSchema.Column c)
    • removeColumn

      public CsvSchema.Builder removeColumn(int index)
      Since:
      2.16
    • dropLastColumnIfEmpty

      public void dropLastColumnIfEmpty()
      Helper method called to drop the last collected column name if it is empty: called if {link CsvParser.Feature#ALLOW_TRAILING_COMMA} enabled to remove the last entry after being added initially.
      Since:
      2.11.2
    • setColumnType

      public CsvSchema.Builder setColumnType(int index, CsvSchema.ColumnType type)
    • removeArrayElementSeparator

      public CsvSchema.Builder removeArrayElementSeparator(int index)
    • setArrayElementSeparator

      public CsvSchema.Builder setArrayElementSeparator(int index, String sep)
      Since:
      2.7
    • setAnyPropertyName

      public CsvSchema.Builder setAnyPropertyName(String name)
    • clearColumns

      public CsvSchema.Builder clearColumns()
    • size

      public int size()
    • getColumns

      public Iterator<CsvSchema.Column> getColumns()
    • hasColumn

      public boolean hasColumn(String name)

      NOTE: this method requires linear scan over existing columns so it may be more efficient to use other types of lookups if available (for example, CsvSchema.column(String) has a hash lookup to use).

      Since:
      2.9
    • setUseHeader

      public CsvSchema.Builder setUseHeader(boolean b)
      Method for specifying whether Schema should indicate that a header line (first row that contains column names) is to be used for reading and writing or not.
    • setReorderColumns

      public CsvSchema.Builder setReorderColumns(boolean b)
      Use in combination with setUseHeader. When use header flag is is set, this setting will reorder the columns defined in this schema to match the order set by the header.
      Parameters:
      b - Enable / Disable this setting
      Returns:
      This Builder instance
      Since:
      2.7
    • setStrictHeaders

      public CsvSchema.Builder setStrictHeaders(boolean b)
      Use in combination with setUseHeader(boolean). When `strict-headers` is set, encoder will ensure the headers are in the order of the schema; if order differs, an exception is thrown.
      Parameters:
      b - Enable / Disable this setting
      Returns:
      This Builder instance
      Since:
      2.7
    • setSkipFirstDataRow

      public CsvSchema.Builder setSkipFirstDataRow(boolean b)
      Method for specifying whether Schema should indicate that the first line that is not a header (if header handling enabled) should be skipped in its entirety.
    • setAllowComments

      public CsvSchema.Builder setAllowComments(boolean b)
      Method for specifying whether Schema should indicate that "hash comments" (lines where the first non-whitespace character is '#') are allowed; if so, they will be skipped without processing.
      Since:
      2.5
    • _feature

      protected final void _feature(int feature, boolean state)
    • setColumnSeparator

      public CsvSchema.Builder setColumnSeparator(char c)
      Method for specifying character used to separate column values. Default is comma (',').
    • setArrayElementSeparator

      @Deprecated public CsvSchema.Builder setArrayElementSeparator(char c)
      Deprecated.
      Since:
      2.5
    • setArrayElementSeparator

      public CsvSchema.Builder setArrayElementSeparator(String separator)
      Method for specifying character used to separate array element values. Default value is semicolon (";")
      Since:
      2.7
    • disableElementSeparator

      @Deprecated public CsvSchema.Builder disableElementSeparator(char c)
      Deprecated.
      Since:
      2.5
    • disableArrayElementSeparator

      public CsvSchema.Builder disableArrayElementSeparator()
      Since:
      2.7
    • setQuoteChar

      public CsvSchema.Builder setQuoteChar(char c)
      Method for specifying character used for optional quoting of values. Default is double-quote ('"').
    • disableQuoteChar

      public CsvSchema.Builder disableQuoteChar()
      Since:
      2.4
    • setEscapeChar

      public CsvSchema.Builder setEscapeChar(char c)
      Method for specifying character used for optional escaping of characters in quoted String values. Default is "not used", meaning that no escaping used.
    • disableEscapeChar

      public CsvSchema.Builder disableEscapeChar()
      Method for specifying that no escape character is to be used with CSV documents this schema defines.
    • setLineSeparator

      public CsvSchema.Builder setLineSeparator(String lf)
    • setLineSeparator

      public CsvSchema.Builder setLineSeparator(char lf)
    • setNullValue

      public CsvSchema.Builder setNullValue(String nvl)
    • setNullValue

      public CsvSchema.Builder setNullValue(char[] nvl)
    • build

      public CsvSchema build()
    • _checkIndex

      protected void _checkIndex(int index)