Top Description Methods
com.univocity.parsers.common.fields

public Interface ColumnMapper

extends Cloneable
Known Direct Implementers
com.univocity.parsers.common.fields.ColumnMapping
Imports
com.univocity.parsers.annotations.*, java.util.*

A utility that allows users to manually define mappings from attributes/methods of a given class to columns to be parsed or written. This removes the requirement of having classes annotated with Parsed or Nested. Mappings defined manually take precedence over annotations.
See Also
ColumnMapping

Method Summary

Modifier and TypeMethod and Description
public void
attributesToColumnNames(Map<String, String>
a map of attribute names associated with a corresponding column name, where:
  • Each key is the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.
  • Each value is the name of the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;
mappings
)

Maps multiple attributes to multiple column names.

public void
attributesToColumns(Map<String, Enum<?>>
a map of attribute names associated with a corresponding column, where:
  • Each key is the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.
  • Each value is an enumeration representing the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;
mappings
)

Maps multiple attributes to multiple columns.

public void
attributesToIndexes(Map<String, Integer>
a map of attribute names associated with a corresponding column, where:
  • Each key is the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.
  • Each value is an integer representing the position of the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;
mappings
)

Maps multiple attributes to multiple column positions.

public void
attributeToColumn(String
the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.
attributeName
,
Enum<?>
an enumeration representing the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;
column
)

Maps an attribute to a column.

public void
attributeToColumnName(String
the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.
attributeName
,
String
the name of the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;
columnName
)

Maps an attribute to a column name.

public void
attributeToIndex(String
the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.
attributeName
,
int
the position of the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;
columnIndex
)

Maps an attribute to a column position.

public ColumnMapper

Returns:

a clone of the current mappings.
clone
()

Creates a deep copy of this object with all its mappings.

public void
methodsToColumnNames(Map<String, String>
a map of methods names associated with a corresponding column name, where:
  • Each key is the name of a method. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, from a Contact attribute inside a Customer class.
  • Each value is the name of the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;
mappings
)

Maps multiple methods to multiple column names.

public void
methodsToColumns(Map<String, Enum<?>>
a map of methods names associated with a corresponding column, where:
  • Each key is the name of a method. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, from a Contact attribute inside a Customer class.
  • Each value is an enumeration representing the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;
mappings
)

Maps multiple methods to multiple columns.

public void
methodsToIndexes(Map<String, Integer>
a map of methods names associated with a corresponding column position, where:
  • Each key is the name of a method. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, from a Contact attribute inside a Customer class.
  • Each value is an integer representing the position of the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;
mappings
)

Maps multiple methods to multiple column positions.

public void
methodToColumn(String
the name of the setter method. Use the dot character to access methods of nested objects, e.g. contact.mobile will target the setter method "mobile(String)" from a Contact attribute inside a Customer class.
setterName
,
Class<?>
the type of the parameter used in the given setter name.
parameterType
,
Enum<?>
an enumeration representing the column that when parsing, will be read from to invoke given setter method of an object
column
)

Maps a setter method to a column.

public void
methodToColumn(String
the name of the method. Use the dot character to access methods of nested objects, * e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, * from a Contact attribute inside a Customer class.
methodName
,
Enum<?>
an enumeration representing the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;
column
)

Maps a method to a column.

public void
methodToColumnName(String
the name of the setter method. Use the dot character to access methods of nested objects, e.g. contact.mobile will target the setter method "mobile(String)" from a Contact attribute inside a Customer class.
setterName
,
Class<?>
the type of the parameter used in the given setter name.
parameterType
,
String
the name of the column that when parsing, will be read from to invoke given setter method of an object
columnName
)

Maps a setter method to a column name.

public void
methodToColumnName(String
the name of the method. Use the dot character to access methods of nested objects, e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, from a Contact attribute inside a Customer class.
methodName
,
String
the name of the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;
columnName
)

Maps a method to a column name.

public void
methodToIndex(String
the name of the setter method. Use the dot character to access methods of nested objects, e.g. contact.mobile will target the setter method "mobile(String)" from a Contact attribute inside a Customer class.
setterName
,
Class<?>
the type of the parameter used in the given setter name.
parameterType
,
int
the position of the column that when parsing, will be read from to invoke given setter method of an object
columnIndex
)

Maps a setter method to a column position.

public void
methodToIndex(String
the name of the method. Use the dot character to access methods of nested objects, * e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, * from a Contact attribute inside a Customer class.
methodName
,
int
the position of the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;
columnIndex
)

Maps a method to a column position.

public void
remove(String
the name of the method or attribute to be removed.
methodOrAttributeName
)

Removes any mappings that target a given method or attribute name.

Method Detail

attributesToColumnNamesback to summary
public void attributesToColumnNames(Map<String, String> mappings)

Maps multiple attributes to multiple column names.

Parameters
mappings:Map<String, String>

a map of attribute names associated with a corresponding column name, where:

  • Each key is the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.
  • Each value is the name of the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;
attributesToColumnsback to summary
public void attributesToColumns(Map<String, Enum<?>> mappings)

Maps multiple attributes to multiple columns.

Parameters
mappings:Map<String, Enum<?>>

a map of attribute names associated with a corresponding column, where:

  • Each key is the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.
  • Each value is an enumeration representing the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;
attributesToIndexesback to summary
public void attributesToIndexes(Map<String, Integer> mappings)

Maps multiple attributes to multiple column positions.

Parameters
mappings:Map<String, Integer>

a map of attribute names associated with a corresponding column, where:

  • Each key is the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.
  • Each value is an integer representing the position of the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;
attributeToColumnback to summary
public void attributeToColumn(String attributeName, Enum<?> column)

Maps an attribute to a column.

Parameters
attributeName:String

the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.

column:Enum<?>

an enumeration representing the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;

attributeToColumnNameback to summary
public void attributeToColumnName(String attributeName, String columnName)

Maps an attribute to a column name.

Parameters
attributeName:String

the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.

columnName:String

the name of the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;

attributeToIndexback to summary
public void attributeToIndex(String attributeName, int columnIndex)

Maps an attribute to a column position.

Parameters
attributeName:String

the name of the attribute. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the attribute "mobile" from a Contact attribute inside a Customer class.

columnIndex:int

the position of the column that: (a) when parsing, will be read from to populate the given attribute of an object; (b) when writing, will receive the value of the given attribute of an object;

cloneback to summary
public ColumnMapper clone()

Creates a deep copy of this object with all its mappings. Changes to the clone won't affect the original instance.

Returns:ColumnMapper

a clone of the current mappings.

methodsToColumnNamesback to summary
public void methodsToColumnNames(Map<String, String> mappings)

Maps multiple methods to multiple column names.

Parameters
mappings:Map<String, String>

a map of methods names associated with a corresponding column name, where:

  • Each key is the name of a method. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, from a Contact attribute inside a Customer class.
  • Each value is the name of the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;
methodsToColumnsback to summary
public void methodsToColumns(Map<String, Enum<?>> mappings)

Maps multiple methods to multiple columns.

Parameters
mappings:Map<String, Enum<?>>

a map of methods names associated with a corresponding column, where:

  • Each key is the name of a method. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, from a Contact attribute inside a Customer class.
  • Each value is an enumeration representing the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;
methodsToIndexesback to summary
public void methodsToIndexes(Map<String, Integer> mappings)

Maps multiple methods to multiple column positions.

Parameters
mappings:Map<String, Integer>

a map of methods names associated with a corresponding column position, where:

  • Each key is the name of a method. Use the dot character to access attributes of nested objects, e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, from a Contact attribute inside a Customer class.
  • Each value is an integer representing the position of the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;
methodToColumnback to summary
public void methodToColumn(String setterName, Class<?> parameterType, Enum<?> column)

Maps a setter method to a column. Use when methodToColumnName(String, String) is not enough to uniquely identify the method you need (e.g. when there are overloaded methods with different parameter types) Used only for parsing. Will be ignored when writing.

Parameters
setterName:String

the name of the setter method. Use the dot character to access methods of nested objects, e.g. contact.mobile will target the setter method "mobile(String)" from a Contact attribute inside a Customer class.

parameterType:Class<?>

the type of the parameter used in the given setter name.

column:Enum<?>

an enumeration representing the column that when parsing, will be read from to invoke given setter method of an object

methodToColumnback to summary
public void methodToColumn(String methodName, Enum<?> column)

Maps a method to a column. When parsing, only "setter" methods will be used i.e. the given method accepts one parameter. If the method is overridden, use methodToColumnName(String, Class, String) to specify the exact parameter type to match the appropriate setter method. When writing, only "getter" methods will be used i.e. the given method doesn't accept any parameters and returns a value.

Parameters
methodName:String

the name of the method. Use the dot character to access methods of nested objects, * e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, * from a Contact attribute inside a Customer class.

column:Enum<?>

an enumeration representing the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;

methodToColumnNameback to summary
public void methodToColumnName(String setterName, Class<?> parameterType, String columnName)

Maps a setter method to a column name. Use when methodToColumnName(String, String) is not enough to uniquely identify the method you need (e.g. when there are overloaded methods with different parameter types) Used only for parsing. Will be ignored when writing.

Parameters
setterName:String

the name of the setter method. Use the dot character to access methods of nested objects, e.g. contact.mobile will target the setter method "mobile(String)" from a Contact attribute inside a Customer class.

parameterType:Class<?>

the type of the parameter used in the given setter name.

columnName:String

the name of the column that when parsing, will be read from to invoke given setter method of an object

methodToColumnNameback to summary
public void methodToColumnName(String methodName, String columnName)

Maps a method to a column name. When parsing, only "setter" methods will be used i.e. the given method accepts one parameter. If the method is overridden, use methodToColumnName(String, Class, String) to specify the exact parameter type to match the appropriate setter method. When writing, only "getter" methods will be used i.e. the given method doesn't accept any parameters and returns a value.

Parameters
methodName:String

the name of the method. Use the dot character to access methods of nested objects, e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, from a Contact attribute inside a Customer class.

columnName:String

the name of the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;

methodToIndexback to summary
public void methodToIndex(String setterName, Class<?> parameterType, int columnIndex)

Maps a setter method to a column position. Use when methodToColumnName(String, String) is not enough to uniquely identify the method you need (e.g. when there are overloaded methods with different parameter types) Used only for parsing. Will be ignored when writing.

Parameters
setterName:String

the name of the setter method. Use the dot character to access methods of nested objects, e.g. contact.mobile will target the setter method "mobile(String)" from a Contact attribute inside a Customer class.

parameterType:Class<?>

the type of the parameter used in the given setter name.

columnIndex:int

the position of the column that when parsing, will be read from to invoke given setter method of an object

methodToIndexback to summary
public void methodToIndex(String methodName, int columnIndex)

Maps a method to a column position. When parsing, only "setter" methods will be used i.e. the given method accepts one parameter. If the method is overridden, use methodToColumnName(String, Class, String) to specify the exact parameter type to match the appropriate setter method. When writing, only "getter" methods will be used i.e. the given method doesn't accept any parameters and returns a value.

Parameters
methodName:String

the name of the method. Use the dot character to access methods of nested objects, * e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing, * from a Contact attribute inside a Customer class.

columnIndex:int

the position of the column that: (a) when parsing, will be read from to invoke given setter method of an object; (b) when writing, will receive the value returned by the given getter method of an object;

removeback to summary
public void remove(String methodOrAttributeName)

Removes any mappings that target a given method or attribute name.

Parameters
methodOrAttributeName:String

the name of the method or attribute to be removed.