T
- Type of the bean being populatedI
- Type of the index into a multivalued fieldpublic interface BeanField<T,I>
Field
class to include
functionality that opencsv requires.
This includes a required flag and a
write(java.lang.Object, java.lang.Object)
method for writing beans
back out to a CSV file. The required flag determines if the field has to be
non-empty.
Synchronization: All implementations of this interface must be thread-safe.
Modifier and Type | Method and Description |
---|---|
Locale |
getErrorLocale()
Returns the error locale for the beans.
|
Field |
getField()
Gets the field to be processed.
|
Object |
getFieldValue(Object bean)
Gets the contents of the selected field of the given bean.
|
Class<?> |
getType()
Gets the type of the bean this field is attached to.
|
Object[] |
indexAndSplitMultivaluedField(Object value,
I index)
Given the value of a bean field and an index into that value, determine
what values need to be written.
|
boolean |
isRequired()
Answers the query, whether this field is required or not.
|
void |
setErrorLocale(Locale errorLocale)
Sets the locale for all error messages.
|
void |
setField(Field field)
Sets the field to be processed.
|
void |
setFieldValue(Object bean,
String value,
String header)
Populates the selected field of the bean.
|
void |
setRequired(boolean required)
Determines whether or not a field is required.
|
void |
setType(Class<?> type)
Sets the type of the bean this field is attached to.
|
String[] |
write(Object bean,
I index)
This method takes the current value of the field in question in the bean
passed in and converts it to one or more strings.
|
Class<?> getType()
void setType(Class<?> type)
type
- The type that is instantiated when this field is usedvoid setField(Field field)
field
- Which field is being populatedboolean isRequired()
void setRequired(boolean required)
required
- Whether or not the field is requiredvoid setFieldValue(Object bean, String value, String header) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException, CsvConstraintViolationException, CsvValidationException
bean
- Object containing the field to be set.value
- String containing the value to set the field to.header
- The header from the CSV file under which this value was found.CsvDataTypeMismatchException
- When the result of data conversion returns
an object that cannot be assigned to the selected fieldCsvRequiredFieldEmptyException
- When a field is mandatory, but there is no
input datum in the CSV fileCsvConstraintViolationException
- When the internal structure of
data would be violated by the data in the CSV fileCsvValidationException
- If a user-supplied validator determines
that the input is invalidObject getFieldValue(Object bean)
bean
- Object containing the field to be readObject[] indexAndSplitMultivaluedField(Object value, I index) throws CsvDataTypeMismatchException
value
- The value of the bean field that should be writtenindex
- An index into value
that determines which of the
many possible values are currently being written. For header-based
mapping strategies, this will be the header name, and for column
position mapping strategies, it will be the zero-based column position.Object
s that should be converted for the
output and writtenCsvDataTypeMismatchException
- If value
is not of the type
expected by the implementing classString[] write(Object bean, I index) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException
bean
- The bean holding the field to be writtenindex
- The header name or column number of the field currently
being processed. This can be used to find a certain position in a
multivalued field when not all of the values should be written.BeanFieldJoin
may return multiple values.
If either the bean or the field are null
, this method returns
an empty array to allow the writer to treat null
specially. It
is also possible that individual values in the array are null
.
The writer may wish to write "(null)" or "\0" or "NULL" or some other
key instead of a blank string.CsvDataTypeMismatchException
- If expected to convert an
unsupported data typeCsvRequiredFieldEmptyException
- If the field is marked as required,
but is currently emptyvoid setErrorLocale(Locale errorLocale)
errorLocale
- Locale for error messages. If null, the default locale
is used.Locale getErrorLocale()
Copyright © 2005–2023. All rights reserved.