Class HeaderColumnNameMappingStrategy<T>
java.lang.Object
com.opencsv.bean.AbstractMappingStrategy<String, String, ComplexFieldMapEntry<String,String,T>, T>
com.opencsv.bean.HeaderNameBaseMappingStrategy<T>
com.opencsv.bean.HeaderColumnNameMappingStrategy<T>
- Type Parameters:
T- Type of the bean to be returned
- All Implemented Interfaces:
MappingStrategy<T>
- Direct Known Subclasses:
FuzzyMappingStrategy
Maps data to objects using the column names in the first row of the CSV file
as reference. This way the column order does not matter.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMappingStrategy
AbstractMappingStrategy.RecursiveType -
Field Summary
Fields inherited from class HeaderNameBaseMappingStrategy
fieldMap, forceCorrectRecordLength, writeOrderFields inherited from class AbstractMappingStrategy
errorLocale, headerIndex, profile, recursiveTypeTree, type -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.HeaderColumnNameMappingStrategy(boolean forceCorrectRecordLength) Constructor to allow setting options for header name mapping. -
Method Summary
Modifier and TypeMethodDescriptionprotected Set<Class<? extends Annotation>> Returns a set of the annotations that are used for binding in this mapping strategy.protected voidloadAnnotatedFieldMap(org.apache.commons.collections4.ListValuedMap<Class<?>, Field> fields) Creates a map of annotated fields in the bean to be processed.private voidregisterBinding(CsvBindByName annotation, Class<?> localType, Field localField) Register a binding between a bean field and a simple converter.private voidregisterCustomBinding(CsvCustomBindByName annotation, Class<?> localType, Field localField) Register a binding between a bean field and a custom converter.private voidregisterJoinBinding(CsvBindAndJoinByName annotation, Class<?> localType, Field localField) Register a binding between a bean field and a multi-valued converter that joins values from multiple columns.private voidregisterSplitBinding(CsvBindAndSplitByName annotation, Class<?> localType, Field localField) Register a binding between a bean field and a collection converter that splits input into multiple values.Methods inherited from class HeaderNameBaseMappingStrategy
captureHeader, chooseMultivaluedFieldIndexFromHeaderIndex, findField, findHeader, getFieldMap, initializeFieldMap, loadUnadornedFieldMap, setColumnOrderOnWrite, verifyLineLengthMethods inherited from class AbstractMappingStrategy
createBean, determineConverter, filterIgnoredFields, generateHeader, getColumnName, getType, ignoreFields, indexBean, instantiateCustomConverter, isForbiddenClassForRecursion, loadFieldMap, loadRecursiveClasses, partitionFields, populateNewBean, selectAnnotationForProfile, setErrorLocale, setFieldValue, setProfile, setType, transmuteBeanMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MappingStrategy
isAnnotationDriven
-
Constructor Details
-
HeaderColumnNameMappingStrategy
public HeaderColumnNameMappingStrategy()Default constructor. Considered stable.- See Also:
-
HeaderColumnNameMappingStrategy
public HeaderColumnNameMappingStrategy(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 useHeaderColumnNameMappingStrategyBuilder.- Parameters:
forceCorrectRecordLength- If set, every record will be shortened or lengthened to match the number of headers- See Also:
-
-
Method Details
-
registerCustomBinding
private void registerCustomBinding(CsvCustomBindByName annotation, Class<?> localType, Field localField) Register a binding between a bean field and a custom converter.- Parameters:
annotation- The annotation attached to the bean fieldlocalType- The class/type in which the field resideslocalField- The bean field
-
registerSplitBinding
private void registerSplitBinding(CsvBindAndSplitByName annotation, Class<?> localType, Field localField) Register a binding between a bean field and a collection converter that splits input into multiple values.- Parameters:
annotation- The annotation attached to the bean fieldlocalType- The class/type in which the field resideslocalField- The bean field
-
registerJoinBinding
private void registerJoinBinding(CsvBindAndJoinByName annotation, Class<?> localType, Field localField) Register a binding between a bean field and a multi-valued converter that joins values from multiple columns.- Parameters:
annotation- The annotation attached to the bean fieldlocalType- The class/type in which the field resideslocalField- The bean field
-
registerBinding
Register a binding between a bean field and a simple converter.- Parameters:
annotation- The annotation attached to the bean fieldlocalType- The class/type in which the field resideslocalField- The bean field
-
loadAnnotatedFieldMap
protected void loadAnnotatedFieldMap(org.apache.commons.collections4.ListValuedMap<Class<?>, Field> fields) Creates a map of annotated fields in the bean to be processed.This method is called by
AbstractMappingStrategy.loadFieldMap()when at least one relevant annotation is found on a member variable.- Overrides:
loadAnnotatedFieldMapin classAbstractMappingStrategy<String, String, ComplexFieldMapEntry<String,String, T>, T> - Parameters:
fields- A list of fields annotated with a binding annotation in the bean to be processed
-
getBindingAnnotations
Returns a set of the annotations that are used for binding in this mapping strategy.In this mapping strategy, those are currently:
- Overrides:
getBindingAnnotationsin classAbstractMappingStrategy<String, String, ComplexFieldMapEntry<String,String, T>, T> - Returns:
- Annotations of the sort
CsvBindByNameorCsvBindByPositionthat are relevant for binding input fields to bean members in this mapping strategy
-