Package com.opencsv.bean
Class FuzzyMappingStrategy<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>
com.opencsv.bean.FuzzyMappingStrategy<T>
- Type Parameters:
T
- The type of bean being processed
- All Implemented Interfaces:
MappingStrategy<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 ClassesModifier and TypeClassDescriptionprivate static class
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
ConstructorsConstructorDescriptionNullary constructor.FuzzyMappingStrategy
(boolean forceCorrectRecordLength) Constructor to allow setting options for header name mapping. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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<Class<?>, 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 Details
-
FuzzyMappingStrategy
public FuzzyMappingStrategy()Nullary constructor. Considered stable.- See Also:
-
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:
-
-
Method Details
-
loadUnadornedFieldMap
protected void loadUnadornedFieldMap(org.apache.commons.collections4.ListValuedMap<Class<?>, 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
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:
IOException
- If parsing failsCsvRequiredFieldEmptyException
- If a field is required, but the header or column position for the field is not present in the input
-