Top Description Inners Fields Constructors Methods
com.opencsv.bean

public abstract Class AbstractMappingStrategy<I, K extends Comparable<K>, C extends ComplexFieldMapEntry<I, K, T>, T>

extends Object
implements MappingStrategy<T>
Class Inheritance
All Implemented Interfaces
com.opencsv.bean.MappingStrategy
Known Direct Subclasses
com.opencsv.bean.ColumnPositionMappingStrategy, com.opencsv.bean.HeaderNameBaseMappingStrategy
Type Parameters
<I>
The initializer type used to build the internal many-to-one mapping
<K>
The type of the key used for internal indexing
<C>
The type of the internal many-to-one mapping
<T>
Type of object that is being processed.
Imports
com.opencsv.ICSVParser, com.opencsv.exceptions.*, org.apache.commons.collections4.ListValuedMap, .MapIterator, .MultiValuedMap, .SetUtils, org.apache.commons.collections4.multimap.ArrayListValuedHashMap, org.apache.commons.lang3.ArrayUtils, .ObjectUtils, .StringUtils, org.apache.commons.lang3.reflect.FieldUtils, java.lang.annotation.Annotation, java.lang.reflect.Field, .InvocationTargetException, java.util.*, java.util.function.Function

This class collects as many generally useful parts of the implementation of a mapping strategy as possible.

This mapping strategy knows of the existence of binding annotations, but assumes through getBindingAnnotations() they are not in use.

Anyone is welcome to use it as a base class for their own mapping strategies.

Author
Andrew Rucker Jones
Since
4.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
AbstractMappingStrategy.RecursiveType

Encapsulates a bean type and all of the member variables that need to be recursed into.

Field Summary

Modifier and TypeField and Description
protected Locale
errorLocale

Locale for error messages.

private static final Set<Class<?>>
FORBIDDEN_CLASSES_FOR_RECURSION

Set of classes where recursion is not allowed.

protected final HeaderIndex
headerIndex

Maintains a bi-directional mapping between column position(s) and header name.

private MultiValuedMap<Class<?>, Field>
ignoredFields

Storage for all manually excluded class/field pairs.

protected String
profile

The profile for configuring bean fields.

protected AbstractMappingStrategy.RecursiveType
recursiveTypeTree

A tree of the types encountered during recursion through the root bean type.

protected Class<? extends T>
type

This is the class of the bean to be manipulated.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
assembleCompleteFieldList(AbstractMappingStrategy.RecursiveType
The root of the type tree at this level of recursion
root
,
final ListValuedMap<Class<?>, Field>
A collection of all fields thus far included in the new representation. This collection will be added to and is the result of this method.
encounteredFields
)

Creates a non-tree (fairly flat) representation of all of the fields bound from all types.

protected abstract K

Returns:

The index to be used for this mapping strategy for BeanField#indexAndSplitMultivaluedField(java.lang.Object, java.lang.Object)
chooseMultivaluedFieldIndexFromHeaderIndex
(int
The current column position while transmuting a bean to CSV output
index
)

For BeanField#indexAndSplitMultivaluedField(java.lang.Object, java.lang.Object) it is necessary to determine which index to pass in.

protected Map<Class<?>, Object>

Returns:

A new instance of the class being mapped.
createBean
()

Implementation will return a bean of the type of object being mapped.

private static void
createSubordinateBeans(AbstractMappingStrategy.RecursiveType typeTree, Map<Class<?>, Object> instanceMap, Object containingObject)

protected CsvConverter

Returns:

The appropriate converter for the necessary conversion
determineConverter
(Field
The field of the bean type in question
field
,
Class<?>
The type to be generated by the converter (on reading)
elementType
,
String
The locale for conversion on reading. May be null or an empty string if a locale is not in use.
locale
,
String
The locale for conversion on writing. May be null or an empty string if a locale is not in use.
writeLocale
,
Class<? extends AbstractCsvConverter>
An optional custom converter
customConverter
)

Given the information provided, determines the appropriate built-in converter to be passed in to the BeanField being created.

protected List<Field>

Returns:

A list of fields that exist for opencsv
filterIgnoredFields
(final Class<?>
The class from which fields come. This must be the class as opencsv would seek to instantiate it, which in the case of inheritance is not necessarily the declaring class.
type
,
Field[]
The fields to be filtered
fields
)

Filters all fields that opencsv has been instructed to ignore and returns a list of the rest.

protected abstract BeanField<T, K>

Returns:

BeanField containing the field for a given column position, or null if one could not be found
findField
(int
The column to find the field for
col
)

Gets the field for a given column position.

public abstract String

Returns:

The name of the header
findHeader
(int
The column number for which the header is sought
col
)

Gets the name (or position number) of the header for the given column number.

public String[]
generateHeader(T bean)

Implements com.opencsv.bean.MappingStrategy.generateHeader.

This method generates a header that can be used for writing beans of the type provided back to a file.

protected Set<Class<? extends Annotation>>

Returns:

Annotations of the sort CsvBindByName or CsvBindByPosition that are relevant for binding input fields to bean members in this mapping strategy
getBindingAnnotations
()

Returns a set of the annotations that are used for binding in this mapping strategy.

protected String

Returns:

The column name or null if the position is larger than the header array or there are no headers defined.
getColumnName
(int
Column position.
col
)

Get the column name for a given column position.

protected abstract FieldMap<I, K, ? extends C, T>

Returns:

The FieldMap used by this strategy
getFieldMap
()

Returns the FieldMap associated with this mapping strategy.

public Class<? extends T>

Returns:

Class of the object that this MappingStrategy will create.
getType
()

Get the class type that the strategy is mapping.

public void
ignoreFields(MultiValuedMap<Class<?>, Field> fields)

Overrides default com.opencsv.bean.MappingStrategy.ignoreFields.

When processing a bean for reading or writing, ignore the given fields from the given classes completely, including all annotations and requirements.

protected Map<Class<?>, Object>

Returns:

The index from type to instance
indexBean
(T
The root bean to be indexed
bean
)

Creates an index of necessary types according to the mapping strategy and existing instances of (subordinate) beans.

private static void
indexSubordinateBeans(AbstractMappingStrategy.RecursiveType typeTree, Map<Class<?>, Object> instanceMap, Object containingObject)

protected abstract void
initializeFieldMap()

Creates an empty binding-type-specific field map that can be filled in later steps.

protected BeanField<T, K>

Returns:

The custom converter
instantiateCustomConverter
(Class<? extends AbstractBeanField<T, K>>
The class for a custom converter
converter
)

Attempts to instantiate the class of the custom converter specified.

protected boolean
isForbiddenClassForRecursion(Class<?>
Class to be checked
type
)

Returns: Whether the type may be recursed into (false), or must be considered a leaf node for recursion (true).

protected void
loadAnnotatedFieldMap(ListValuedMap<Class<?>, Field>
A list of fields annotated with a binding annotation in the bean to be processed
fields
)

Creates a map of annotated fields in the bean to be processed.

protected void
loadFieldMap()

Builds a map of columns from the input to fields of the bean type.

protected AbstractMappingStrategy.RecursiveType

Returns:

A representation of this type and all of the types beneath it in a tree
loadRecursiveClasses
(Class<?>
The type that is meant to be added to the tree
newType
,
Set<Class<?>>
A set of types already encountered during recursion, as types may not be recursed into more than once.
encounteredTypes
)

Creates a tree of beans embedded in each other.

protected abstract void
loadUnadornedFieldMap(ListValuedMap<Class<?>, Field>
A list of all non-synthetic fields in the bean to be processed
fields
)

Creates a map of fields in the bean to be processed that have no annotations.

protected Map<Boolean, ListValuedMap<Class<?>, Field>>

Returns:

A multi-valued map (class to multiple fields in that class) in which all annotated fields are mapped under Boolean#TRUE, and all non-annotated fields are mapped under Boolean#FALSE.
partitionFields
()

Partitions all non-synthetic fields of the bean type being processed into annotated and non-annotated fields according to getBindingAnnotations().

public T
populateNewBean(String[] line)

Implements com.opencsv.bean.MappingStrategy.populateNewBean.

Takes a line of input from a CSV file and creates a bean out of it.

protected <
The annotation type being tested
A extends Annotation
>
A

Returns:

The annotation with the appropriate profile or null if nothing appropriate is found
selectAnnotationForProfile
(A[]
All annotations of a given type
annotations
,
Function<A, String[]>
A function mapping an annotation of type A to the list of profiles it applies to
getProfiles
)

Determines which one of a list of annotations applies to the currently selected profile.

public void
setErrorLocale(Locale errorLocale)

Overrides default com.opencsv.bean.MappingStrategy.setErrorLocale.

Sets the locale for all error messages.

protected void
setFieldValue(Map<Class<?>, Object>
Object containing the field to be set.
beanTree
,
String
String containing the value to set the field to.
value
,
int
The column position from the CSV file under which this value was found.
column
)

Populates the field corresponding to the column position indicated of the bean passed in according to the rules of the mapping strategy.

public void
setProfile(String profile)

Overrides default com.opencsv.bean.MappingStrategy.setProfile.

Sets the profile this mapping strategy will use when configuring bean fields.

public void
setType(Class<? extends T> type)

Implements com.opencsv.bean.MappingStrategy.setType.

Sets the class type that is being mapped.

public String[]
transmuteBean(T bean)

Implements com.opencsv.bean.MappingStrategy.transmuteBean.

Transmutes a bean instance into an array of Strings to be written to a CSV file.

protected abstract void
verifyLineLength(int
The number of fields present in the line of input
numberOfFields
)

Must be called once the length of input for a line/record is known to verify that the line was complete.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

errorLocaleback to summary
protected Locale errorLocale

Locale for error messages.

FORBIDDEN_CLASSES_FOR_RECURSIONback to summary
private static final Set<Class<?>> FORBIDDEN_CLASSES_FOR_RECURSION

Set of classes where recursion is not allowed. Using HashSet because, given the large number of types, the contains method is quicker than an Array or ArrayList (Granted the number where Set is more efficient is different per Java release and system configuration). And being a Set we are noting that each value is unique.

headerIndexback to summary
protected final HeaderIndex headerIndex

Maintains a bi-directional mapping between column position(s) and header name.

ignoredFieldsback to summary
private MultiValuedMap<Class<?>, Field> ignoredFields

Storage for all manually excluded class/field pairs.

profileback to summary
protected String profile

The profile for configuring bean fields.

recursiveTypeTreeback to summary
protected AbstractMappingStrategy.RecursiveType recursiveTypeTree

A tree of the types encountered during recursion through the root bean type. These are only the types (and associated fields) specifically annotated with CsvRecurse.

typeback to summary
protected Class<? extends T> type

This is the class of the bean to be manipulated.

Constructor Detail

AbstractMappingStrategyback to summary
public AbstractMappingStrategy()

Method Detail

assembleCompleteFieldListback to summary
private void assembleCompleteFieldList(AbstractMappingStrategy.RecursiveType root, final ListValuedMap<Class<?>, Field> encounteredFields)

Creates a non-tree (fairly flat) representation of all of the fields bound from all types. This method is used recursively.

Parameters
root:AbstractMappingStrategy.RecursiveType

The root of the type tree at this level of recursion

encounteredFields:ListValuedMap<Class<?>, Field>

A collection of all fields thus far included in the new representation. This collection will be added to and is the result of this method.

chooseMultivaluedFieldIndexFromHeaderIndexback to summary
protected abstract K chooseMultivaluedFieldIndexFromHeaderIndex(int index)

For BeanField#indexAndSplitMultivaluedField(java.lang.Object, java.lang.Object) it is necessary to determine which index to pass in.

Parameters
index:int

The current column position while transmuting a bean to CSV output

Returns:K

The index to be used for this mapping strategy for BeanField#indexAndSplitMultivaluedField(java.lang.Object, java.lang.Object)

createBeanback to summary
protected Map<Class<?>, Object> createBean() throws CsvBeanIntrospectionException, IllegalStateException

Implementation will return a bean of the type of object being mapped.

Returns:Map<Class<?>, Object>

A new instance of the class being mapped.

Exceptions
CsvBeanIntrospectionException:
Thrown on error creating object.
IllegalStateException:
If the type of the bean has not been initialized through setType(java.lang.Class)
createSubordinateBeansback to summary
private static void createSubordinateBeans(AbstractMappingStrategy.RecursiveType typeTree, Map<Class<?>, Object> instanceMap, Object containingObject) throws InstantiationException, IllegalAccessException, InvocationTargetException, IllegalArgumentException, NoSuchMethodException, SecurityException
determineConverterback to summary
protected CsvConverter determineConverter(Field field, Class<?> elementType, String locale, String writeLocale, Class<? extends AbstractCsvConverter> customConverter) throws CsvBadConverterException

Given the information provided, determines the appropriate built-in converter to be passed in to the BeanField being created.

Parameters
field:Field

The field of the bean type in question

elementType:Class<?>

The type to be generated by the converter (on reading)

locale:String

The locale for conversion on reading. May be null or an empty string if a locale is not in use.

writeLocale:String

The locale for conversion on writing. May be null or an empty string if a locale is not in use.

customConverter:Class<? extends AbstractCsvConverter>

An optional custom converter

Returns:CsvConverter

The appropriate converter for the necessary conversion

Exceptions
CsvBadConverterException:
If the converter cannot be instantiated
Since
4.2
filterIgnoredFieldsback to summary
protected List<Field> filterIgnoredFields(final Class<?> type, Field[] fields)

Filters all fields that opencsv has been instructed to ignore and returns a list of the rest.

Parameters
type:Class<?>

The class from which fields come. This must be the class as opencsv would seek to instantiate it, which in the case of inheritance is not necessarily the declaring class.

fields:Field[]

The fields to be filtered

Returns:List<Field>

A list of fields that exist for opencsv

findFieldback to summary
protected abstract BeanField<T, K> findField(int col)

Gets the field for a given column position.

Parameters
col:int

The column to find the field for

Returns:BeanField<T, K>

BeanField containing the field for a given column position, or null if one could not be found

Exceptions
CsvBadConverterException:
If a custom converter for a field cannot be initialized
findHeaderback to summary
public abstract String findHeader(int col)

Gets the name (or position number) of the header for the given column number. The column numbers are zero-based.

Parameters
col:int

The column number for which the header is sought

Returns:String

The name of the header

generateHeaderback to summary
public String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException

Implements com.opencsv.bean.MappingStrategy.generateHeader.

This method generates a header that can be used for writing beans of the type provided back to a file.

The ordering of the headers is determined by the com.opencsv.bean.FieldMap in use.

This method should be called first by all overriding classes to make certain headerIndex is properly initialized.

Annotations
@Override
Exceptions
CsvRequiredFieldEmptyException:

Doc from com.opencsv.bean.MappingStrategy.generateHeader.

If a required header is missing while attempting to write. Since every other header is hard-wired through the bean fields and their associated annotations, this can only happen with multi-valued fields.

getBindingAnnotationsback to summary
protected Set<Class<? extends Annotation>> getBindingAnnotations()

Returns a set of the annotations that are used for binding in this mapping strategy. The default implementation returns the empty set.

Returns:Set<Class<? extends Annotation>>

Annotations of the sort CsvBindByName or CsvBindByPosition that are relevant for binding input fields to bean members in this mapping strategy

Since
5.0
getColumnNameback to summary
protected String getColumnName(int col)

Get the column name for a given column position.

Parameters
col:int

Column position.

Returns:String

The column name or null if the position is larger than the header array or there are no headers defined.

getFieldMapback to summary
protected abstract FieldMap<I, K, ? extends C, T> getFieldMap()

Returns the FieldMap associated with this mapping strategy.

Returns:FieldMap<I, K, ? extends C, T>

The FieldMap used by this strategy

getTypeback to summary
public Class<? extends T> getType()

Get the class type that the strategy is mapping.

Returns:Class<? extends T>

Class of the object that this MappingStrategy will create.

ignoreFieldsback to summary
public void ignoreFields(MultiValuedMap<Class<?>, Field> fields) throws IllegalArgumentException

Overrides default com.opencsv.bean.MappingStrategy.ignoreFields.

Doc from com.opencsv.bean.MappingStrategy.ignoreFields.

When processing a bean for reading or writing, ignore the given fields from the given classes completely, including all annotations and requirements. This method has two compelling applications:

  1. If you are not able to modify the source code of the beans you use, or
  2. If you use a mapping strategy without annotations and want to exclude a small number of fields from a bean with a large number of fields.

Calling this method overwrites the fields passed in from any previous calls. It is legal to call this method before calling setType(Class), and it may be more efficient to do so.

Caution must be exercised with this method when letting opencsv automatically determine the mapping strategy. When a field is ignored, opencsv pretends it does not exist at all. If, for instance, all fields annotated with opencsv binding annotations are ignored, opencsv will automatically switch to HeaderColumnNameMappingStrategy and assume header names exactly match field names.

An implementation of this interface is not required to implement this method. The default implementation throws UnsupportedOperationException.

Annotations
@Override
Exceptions
IllegalArgumentException:
If any entry in the map has a null key, a null value, or if the value is not a field in the class represented by the key
indexBeanback to summary
protected Map<Class<?>, Object> indexBean(T bean) throws IllegalAccessException, InvocationTargetException

Creates an index of necessary types according to the mapping strategy and existing instances of (subordinate) beans.

Parameters
bean:T

The root bean to be indexed

Returns:Map<Class<?>, Object>

The index from type to instance

Exceptions
IllegalAccessException:
If there are problems accessing a subordinate bean
InvocationTargetException:
If there are problems accessing a subordinate bean
Since
5.0
indexSubordinateBeansback to summary
private static void indexSubordinateBeans(AbstractMappingStrategy.RecursiveType typeTree, Map<Class<?>, Object> instanceMap, Object containingObject) throws IllegalAccessException, InvocationTargetException
initializeFieldMapback to summary
protected abstract void initializeFieldMap()

Creates an empty binding-type-specific field map that can be filled in later steps.

This method may be called multiple times and must erase any state information from previous calls.

Since
5.0
instantiateCustomConverterback to summary
protected BeanField<T, K> instantiateCustomConverter(Class<? extends AbstractBeanField<T, K>> converter) throws CsvBadConverterException

Attempts to instantiate the class of the custom converter specified.

Parameters
converter:Class<? extends AbstractBeanField<T, K>>

The class for a custom converter

Returns:BeanField<T, K>

The custom converter

Exceptions
CsvBadConverterException:
If the class cannot be instantiated
isForbiddenClassForRecursionback to summary
protected boolean isForbiddenClassForRecursion(Class<?> type)
Parameters
type:Class<?>

Class to be checked

Returns:boolean

Whether the type may be recursed into (false), or must be considered a leaf node for recursion (true). This implementation considers the boxed primitives forbidden.

loadAnnotatedFieldMapback to summary
protected void loadAnnotatedFieldMap(ListValuedMap<Class<?>, Field> fields)

Creates a map of annotated fields in the bean to be processed.

This method is called by loadFieldMap() when at least one relevant annotation is found on a member variable.

The default implementation assumes there are no annotations and does nothing.

Parameters
fields:ListValuedMap<Class<?>, Field>

A list of fields annotated with a binding annotation in the bean to be processed

Since
5.0
loadFieldMapback to summary
protected void loadFieldMap() throws CsvBadConverterException

Builds a map of columns from the input to fields of the bean type.

Exceptions
CsvBadConverterException:
If there is a problem instantiating the custom converter for an annotated field
loadRecursiveClassesback to summary
protected AbstractMappingStrategy.RecursiveType loadRecursiveClasses(Class<?> newType, Set<Class<?>> encounteredTypes)

Creates a tree of beans embedded in each other. These are the member variables annotated with CsvRecurse and their associated types. This method is used recursively.

Parameters
newType:Class<?>

The type that is meant to be added to the tree

encounteredTypes:Set<Class<?>>

A set of types already encountered during recursion, as types may not be recursed into more than once.

Returns:AbstractMappingStrategy.RecursiveType

A representation of this type and all of the types beneath it in a tree

Exceptions
CsvRecursionException:
If recursion is attempted into a primitive type or a previously encountered type is added again or a member variable annotated with CsvRecurse is also annotated with a binding annotation
loadUnadornedFieldMapback to summary
protected abstract void loadUnadornedFieldMap(ListValuedMap<Class<?>, Field> fields)

Creates a map of fields in the bean to be processed that have no annotations. This method is called by loadFieldMap() when absolutely no annotations that are relevant for this mapping strategy are found in the type of bean being processed.

Parameters
fields:ListValuedMap<Class<?>, Field>

A list of all non-synthetic fields in the bean to be processed

Since
5.0
partitionFieldsback to summary
protected Map<Boolean, ListValuedMap<Class<?>, Field>> partitionFields()

Partitions all non-synthetic fields of the bean type being processed into annotated and non-annotated fields according to getBindingAnnotations().

Returns:Map<Boolean, ListValuedMap<Class<?>, Field>>

A multi-valued map (class to multiple fields in that class) in which all annotated fields are mapped under Boolean#TRUE, and all non-annotated fields are mapped under Boolean#FALSE.

Since
5.0
populateNewBeanback to summary
public T populateNewBean(String[] line) throws CsvBeanIntrospectionException, CsvFieldAssignmentException, CsvChainedException

Implements com.opencsv.bean.MappingStrategy.populateNewBean.

Doc from com.opencsv.bean.MappingStrategy.populateNewBean.

Takes a line of input from a CSV file and creates a bean out of it.

Annotations
@SuppressWarnings:unchecked
@Override
Exceptions
CsvBeanIntrospectionException:
Generally, if some part of the bean cannot be accessed and used as needed
CsvFieldAssignmentException:
A more specific subclass of this exception is thrown for any problem decoding and assigning a field of the input to a bean field
CsvChainedException:
If multiple exceptions are thrown for the same input line
selectAnnotationForProfileback to summary
protected <A extends Annotation> A selectAnnotationForProfile(A[] annotations, Function<A, String[]> getProfiles)

Determines which one of a list of annotations applies to the currently selected profile. If no annotation specific to the profile is found, the annotation for the default profile is returned. If neither is found, null is returned.

Parameters
<A>
The annotation type being tested
annotations:A[]

All annotations of a given type

getProfiles:Function<A, String[]>

A function mapping an annotation of type A to the list of profiles it applies to

Returns:A

The annotation with the appropriate profile or null if nothing appropriate is found

Since
5.4
setErrorLocaleback to summary
public void setErrorLocale(Locale errorLocale)

Overrides default com.opencsv.bean.MappingStrategy.setErrorLocale.

Doc from com.opencsv.bean.MappingStrategy.setErrorLocale.

Sets the locale for all error messages. The default implementation does nothing, as it is expected that most implementations of this interface will not support multiple languages.

Annotations
@Override
setFieldValueback to summary
protected void setFieldValue(Map<Class<?>, Object> beanTree, String value, int column) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException, CsvConstraintViolationException, CsvValidationException

Populates the field corresponding to the column position indicated of the bean passed in according to the rules of the mapping strategy. This method performs conversion on the input string and assigns the result to the proper field in the provided bean.

Parameters
beanTree:Map<Class<?>, Object>

Object containing the field to be set.

value:String

String containing the value to set the field to.

column:int

The column position from the CSV file under which this value was found.

Exceptions
CsvDataTypeMismatchException:
When the result of data conversion returns an object that cannot be assigned to the selected field
CsvRequiredFieldEmptyException:
When a field is mandatory, but there is no input datum in the CSV file
CsvConstraintViolationException:
When the internal structure of data would be violated by the data in the CSV file
CsvValidationException:
If a user-supplied validator determines that the input is invalid
Since
4.2
setProfileback to summary
public void setProfile(String profile)

Overrides default com.opencsv.bean.MappingStrategy.setProfile.

Sets the profile this mapping strategy will use when configuring bean fields.

Annotations
@Override
setTypeback to summary
public void setType(Class<? extends T> type) throws CsvBadConverterException

Implements com.opencsv.bean.MappingStrategy.setType.

Sets the class type that is being mapped. Also initializes the mapping between column names and bean fields and attempts to create one example bean to be certain there are no fundamental problems with creation.

Annotations
@Override
Exceptions
CsvBadConverterException:

Doc from com.opencsv.bean.MappingStrategy.setType.

If a field in the bean is annotated with a custom converter that cannot be initialized. If you are not using custom converters that you have written yourself, it should be safe to catch this exception and ignore it.

transmuteBeanback to summary
public String[] transmuteBean(T bean) throws CsvFieldAssignmentException, CsvChainedException

Implements com.opencsv.bean.MappingStrategy.transmuteBean.

Doc from com.opencsv.bean.MappingStrategy.transmuteBean.

Transmutes a bean instance into an array of Strings to be written to a CSV file.

Annotations
@Override
Exceptions
CsvFieldAssignmentException:
A more specific subclass of this exception is thrown for any problem decoding and assigning a field of the input to a bean field
CsvChainedException:
If multiple exceptions are thrown for the same input line
verifyLineLengthback to summary
protected abstract void verifyLineLength(int numberOfFields) throws CsvRequiredFieldEmptyException

Must be called once the length of input for a line/record is known to verify that the line was complete. Complete in this context means, no required fields are missing. The issue here is, as long as a column is present but empty, we can check whether the field is required and throw an exception if it is not, but if the data end prematurely, we never have this chance without indication that no more data are on the way. Another validation is that the number of fields must match the number of headers to prevent a data mismatch situation.

Parameters
numberOfFields:int

The number of fields present in the line of input

Exceptions
CsvRequiredFieldEmptyException:
If a required column is missing
Since
4.0
com.opencsv.bean back to summary

protected Class AbstractMappingStrategy.RecursiveType

extends Object
Class Inheritance

Encapsulates a bean type and all of the member variables that need to be recursed into.

Field Summary

Modifier and TypeField and Description
private final Map<FieldAccess<Object>, AbstractMappingStrategy.RecursiveType>
private final Class<?>

Constructor Summary

AccessConstructor and Description
protected
RecursiveType(Class<?>
Type associated with this branch
type
)

Constructs a RecursiveType with the specified type.

Method Summary

Modifier and TypeMethod and Description
public void
addRecursiveMember(FieldAccess<Object>
Field access member to add a recursive type to
member
,
AbstractMappingStrategy.RecursiveType memberType)

Used to add a recursive type.

public Map<FieldAccess<Object>, AbstractMappingStrategy.RecursiveType>
getRecursiveMembers()

Returns: Map of field access to RecursiveType.

public Class<?>
getType()

Returns: Type associated with this branch

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

recursiveMembersback to summary
private final Map<FieldAccess<Object>, AbstractMappingStrategy.RecursiveType> recursiveMembers
typeback to summary
private final Class<?> type

Constructor Detail

RecursiveTypeback to summary
protected RecursiveType(Class<?> type)

Constructs a RecursiveType with the specified type.

Parameters
type:Class<?>

Type associated with this branch

Method Detail

addRecursiveMemberback to summary
public void addRecursiveMember(FieldAccess<Object> member, AbstractMappingStrategy.RecursiveType memberType)

Used to add a recursive type.

Parameters
member:FieldAccess<Object>

Field access member to add a recursive type to

memberType:AbstractMappingStrategy.RecursiveType

RecursiveType to add

getRecursiveMembersback to summary
public Map<FieldAccess<Object>, AbstractMappingStrategy.RecursiveType> getRecursiveMembers()
Returns:Map<FieldAccess<Object>, AbstractMappingStrategy.RecursiveType>

Map of field access to RecursiveType.

getTypeback to summary
public Class<?> getType()
Returns:Class<?>

Type associated with this branch