Package com.opencsv.bean
Class HeaderColumnNameTranslateMappingStrategy<T>
java.lang.Object
com.opencsv.bean.AbstractMappingStrategy<String,String,ComplexFieldMapEntry<String,String,T>,T>
com.opencsv.bean.HeaderNameBaseMappingStrategy<T>
com.opencsv.bean.HeaderColumnNameTranslateMappingStrategy<T>
- Type Parameters:
T
- Class to be mapped.
- All Implemented Interfaces:
MappingStrategy<T>
Expands on
HeaderColumnNameMappingStrategy
by allowing the user to
pass in a map of column names to bean names.
This way the fields in the bean do not have to match the fields in the CSV
file. This is only for when the user passes in the header names
programmatically, and not for annotated beans.-
Nested Class Summary
Nested classes/interfaces inherited from class com.opencsv.bean.AbstractMappingStrategy
AbstractMappingStrategy.RecursiveType
-
Field Summary
FieldsFields inherited from class com.opencsv.bean.HeaderNameBaseMappingStrategy
fieldMap, forceCorrectRecordLength, writeOrder
Fields inherited from class com.opencsv.bean.AbstractMappingStrategy
errorLocale, headerIndex, profile, recursiveTypeTree, type
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.HeaderColumnNameTranslateMappingStrategy
(boolean forceCorrectRecordLength) Constructor to allow setting options for header name mapping. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the column mappings of the strategy.getColumnName
(int col) Get the column name for a given column position.void
setColumnMapping
(Map<String, String> columnMapping) Sets the column mapping to those passed in.Methods inherited from class com.opencsv.bean.HeaderNameBaseMappingStrategy
captureHeader, chooseMultivaluedFieldIndexFromHeaderIndex, findField, findHeader, getFieldMap, initializeFieldMap, loadUnadornedFieldMap, setColumnOrderOnWrite, verifyLineLength
Methods inherited from class com.opencsv.bean.AbstractMappingStrategy
createBean, determineConverter, filterIgnoredFields, generateHeader, getBindingAnnotations, getType, ignoreFields, indexBean, instantiateCustomConverter, isForbiddenClassForRecursion, loadAnnotatedFieldMap, loadFieldMap, loadRecursiveClasses, partitionFields, populateNewBean, selectAnnotationForProfile, setErrorLocale, setFieldValue, setProfile, setType, transmuteBean
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.opencsv.bean.MappingStrategy
isAnnotationDriven
-
Field Details
-
columnMapping
-
-
Constructor Details
-
HeaderColumnNameTranslateMappingStrategy
public HeaderColumnNameTranslateMappingStrategy()Default constructor. Considered stable.- See Also:
-
HeaderColumnNameTranslateMappingStrategy
public HeaderColumnNameTranslateMappingStrategy(boolean forceCorrectRecordLength) Constructor to allow setting options for header name mapping. Not considered stable. As new options are introduced for the mapping strategy, they will be introduced here. You are encouraged to useHeaderColumnNameTranslateMappingStrategyBuilder
.- Parameters:
forceCorrectRecordLength
- If set, every record will be shortened or lengthened to match the number of headers- See Also:
-
-
Method Details
-
getColumnName
Description copied from class:AbstractMappingStrategy
Get the column name for a given column position.- Overrides:
getColumnName
in classAbstractMappingStrategy<String,
String, ComplexFieldMapEntry<String, String, T>, T> - Parameters:
col
- Column position.- Returns:
- The column name or null if the position is larger than the header array or there are no headers defined.
-
getColumnMapping
Retrieves the column mappings of the strategy.- Returns:
- The column mappings of the strategy.
-
setColumnMapping
Sets the column mapping to those passed in.- Parameters:
columnMapping
- Source column mapping.
-