Class 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.
  • 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 use HeaderColumnNameMappingStrategyBuilder.
      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 field
      localType - The class/type in which the field resides
      localField - 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 field
      localType - The class/type in which the field resides
      localField - 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 field
      localType - The class/type in which the field resides
      localField - The bean field
    • registerBinding

      private void registerBinding(CsvBindByName annotation, Class<?> localType, Field localField)
      Register a binding between a bean field and a simple converter.
      Parameters:
      annotation - The annotation attached to the bean field
      localType - The class/type in which the field resides
      localField - 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:
      loadAnnotatedFieldMap in class AbstractMappingStrategy<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

      protected Set<Class<? extends 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 class AbstractMappingStrategy<String,String,ComplexFieldMapEntry<String,String,T>,T>
      Returns:
      Annotations of the sort CsvBindByName or CsvBindByPosition that are relevant for binding input fields to bean members in this mapping strategy