Package com.opencsv.bean
Class FuzzyMappingStrategy<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>
-
- com.opencsv.bean.FuzzyMappingStrategy<T>
-
- Type Parameters:
T
- The type of bean being processed
- All Implemented Interfaces:
MappingStrategy<T>
public class FuzzyMappingStrategy<T> extends HeaderColumnNameMappingStrategy<T>
A mapping strategy that tries to make the best match between header names and non-annotated member variables.- Since:
- 5.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FuzzyMappingStrategy.FuzzyComparison
This is a simple class for grouping header name, member variable name, and the result of fuzzy matching in one sortable place.-
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 FuzzyMappingStrategy()
Nullary constructor.FuzzyMappingStrategy(boolean forceCorrectRecordLength)
Constructor to allow setting options for header name mapping.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
captureHeader(CSVReader reader)
Implementation of this method can grab the header line before parsing begins to use to map columns to bean properties.protected void
loadUnadornedFieldMap(org.apache.commons.collections4.ListValuedMap<java.lang.Class<?>,java.lang.reflect.Field> fields)
This implementation intentionally does nothing in order to allow fuzzy matching in case there are no annotations at all in the class in question.-
Methods inherited from class com.opencsv.bean.HeaderColumnNameMappingStrategy
getBindingAnnotations, loadAnnotatedFieldMap
-
Methods inherited from class com.opencsv.bean.HeaderNameBaseMappingStrategy
chooseMultivaluedFieldIndexFromHeaderIndex, findField, findHeader, getFieldMap, initializeFieldMap, 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
-
FuzzyMappingStrategy
public FuzzyMappingStrategy()
Nullary constructor. Considered stable.- See Also:
FuzzyMappingStrategyBuilder
-
FuzzyMappingStrategy
public FuzzyMappingStrategy(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 useFuzzyMappingStrategyBuilder
.- Parameters:
forceCorrectRecordLength
- If set, every record will be shortened or lengthened to match the number of headers- See Also:
FuzzyMappingStrategyBuilder
-
-
Method Detail
-
loadUnadornedFieldMap
protected void loadUnadornedFieldMap(org.apache.commons.collections4.ListValuedMap<java.lang.Class<?>,java.lang.reflect.Field> fields)
This implementation intentionally does nothing in order to allow fuzzy matching in case there are no annotations at all in the class in question.- Overrides:
loadUnadornedFieldMap
in classHeaderNameBaseMappingStrategy<T>
- Parameters:
fields
- A list of all non-synthetic fields in the bean to be processed
-
captureHeader
public void captureHeader(CSVReader reader) throws java.io.IOException, CsvRequiredFieldEmptyException
Description copied from interface:MappingStrategy
Implementation of this method can grab the header line before parsing begins to use to map columns to bean properties.- Specified by:
captureHeader
in interfaceMappingStrategy<T>
- Overrides:
captureHeader
in classHeaderNameBaseMappingStrategy<T>
- Parameters:
reader
- The CSVReader to use for header parsing- Throws:
java.io.IOException
- If parsing failsCsvRequiredFieldEmptyException
- If a field is required, but the header or column position for the field is not present in the input
-
-