Package com.opencsv.bean
Class HeaderColumnNameMappingStrategy<T>
- java.lang.Object
-
- com.opencsv.bean.AbstractMappingStrategy<java.lang.String,java.lang.String,ComplexFieldMapEntry<java.lang.String,java.lang.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
public class HeaderColumnNameMappingStrategy<T> extends HeaderNameBaseMappingStrategy<T>
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 com.opencsv.bean.AbstractMappingStrategy
AbstractMappingStrategy.RecursiveType
-
-
Field Summary
-
Fields 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
Constructors Constructor Description HeaderColumnNameMappingStrategy()
Default constructor.HeaderColumnNameMappingStrategy(boolean forceCorrectRecordLength)
Constructor to allow setting options for header name mapping.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>>
getBindingAnnotations()
Returns a set of the annotations that are used for binding in this mapping strategy.protected void
loadAnnotatedFieldMap(org.apache.commons.collections4.ListValuedMap<java.lang.Class<?>,java.lang.reflect.Field> fields)
Creates a map of annotated fields in the bean to be processed.private void
registerBinding(CsvBindByName annotation, java.lang.Class<?> localType, java.lang.reflect.Field localField)
Register a binding between a bean field and a simple converter.private void
registerCustomBinding(CsvCustomBindByName annotation, java.lang.Class<?> localType, java.lang.reflect.Field localField)
Register a binding between a bean field and a custom converter.private void
registerJoinBinding(CsvBindAndJoinByName annotation, java.lang.Class<?> localType, java.lang.reflect.Field localField)
Register a binding between a bean field and a multi-valued converter that joins values from multiple columns.private void
registerSplitBinding(CsvBindAndSplitByName annotation, java.lang.Class<?> localType, java.lang.reflect.Field localField)
Register a binding between a bean field and a collection converter that splits input into multiple values.-
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, getColumnName, getType, ignoreFields, indexBean, instantiateCustomConverter, isForbiddenClassForRecursion, 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
-
-
-
-
Constructor Detail
-
HeaderColumnNameMappingStrategy
public HeaderColumnNameMappingStrategy()
Default constructor. Considered stable.- See Also:
HeaderColumnNameMappingStrategyBuilder
-
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:
HeaderColumnNameMappingStrategyBuilder
-
-
Method Detail
-
registerCustomBinding
private void registerCustomBinding(CsvCustomBindByName annotation, java.lang.Class<?> localType, java.lang.reflect.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, java.lang.Class<?> localType, java.lang.reflect.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, java.lang.Class<?> localType, java.lang.reflect.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
private void registerBinding(CsvBindByName annotation, java.lang.Class<?> localType, java.lang.reflect.Field localField)
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<java.lang.Class<?>,java.lang.reflect.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:
loadAnnotatedFieldMap
in classAbstractMappingStrategy<java.lang.String,java.lang.String,ComplexFieldMapEntry<java.lang.String,java.lang.String,T>,T>
- Parameters:
fields
- A list of fields annotated with a binding annotation in the bean to be processed
-
getBindingAnnotations
protected java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> getBindingAnnotations()
Returns a set of the annotations that are used for binding in this mapping strategy.In this mapping strategy, those are currently:
- Overrides:
getBindingAnnotations
in classAbstractMappingStrategy<java.lang.String,java.lang.String,ComplexFieldMapEntry<java.lang.String,java.lang.String,T>,T>
- Returns:
- Annotations of the sort
CsvBindByName
orCsvBindByPosition
that are relevant for binding input fields to bean members in this mapping strategy
-
-