All custom converters must be descended from this class.
Internally, opencsv uses another set of classes for the actual conversion, leaving this class mostly to deal with assigment to bean fields.
| Modifier and Type | Field and Description |
|---|---|
| protected CsvConverter | converter
A class that converts from a string to the destination type on reading and vice versa on writing. |
| protected Locale | errorLocale
Locale for error messages. |
| protected Field | field
The field this class represents. |
| protected FieldAccess | fieldAccess
An encapsulated way of accessing the member variable associated with this field. |
| protected boolean | required
Whether or not this field is required. |
| protected Class | type
The type the field is located in. This is not necessarily the declaring class in the case of inheritance, but rather the type that opencsv expects to instantiate. |
| Access | Constructor and Description |
|---|---|
| public | AbstractBeanField()
Default nullary constructor, so derived classes aren't forced to create a constructor identical to this one. |
| public | AbstractBeanField(Class<?>
The type of the class in which this field is found. This is
the type as instantiated by opencsv, and not necessarily the
type in which the field is declared in the case of
inheritance. type, Field A field, boolean java. object.Whether or not this field is required in input required, Locale The errorLocale to use for error messages. errorLocale, CsvConverter The converter to be used to perform the actual data
conversion converter)
|
| Modifier and Type | Method and Description |
|---|---|
| protected void | assignValueToField(Object
The bean in which the field is located bean, Object The data to be assigned to this field of the destination bean obj, String The header from the CSV file under which this value was found. header)Assigns the given object to this field of the destination bean. |
| protected abstract Object | Returns: Anjava. representing the input data converted
into the proper typeThe string from the selected field of the CSV file. If the
field is marked as required in the annotation, this value is guaranteed
not to be null, empty or blank according to
value)org.Method for converting from a string to the proper datatype of the destination field. |
| protected String | Returns: A string representation of the value of the field in question in the bean passed in, or an empty string ifvalue is nullThe contents of the field currently being processed from the
bean to be written. Can be null if the field is not marked as required. value)This is the method that actually performs the conversion from field to
string for |
| public Locale | getErrorLocale()
Implements com. Returns the error locale for the beans. |
| public Field | |
| public Object | getFieldValue(Object bean)
Implements com. Gets the contents of the selected field of the given bean. |
| public Class | getType()
Implements com. Gets the type of the bean this field is attached to. |
| public Object[] | Returns: value wrapped in an array, since we assume most values
will not be multi-valuedImplements com. Given the value of a bean field and an index into that value, determine what values need to be written. |
| protected boolean | Returns: Whether or not this implementation considersvalue to be
empty for the purposes of its conversionThe value of a field out of a bean that is being written to
a CSV file. Can be value)null.Whether or not this implementation of |
| public boolean | isRequired()
Implements com. Answers the query, whether this field is required or not. |
| private String | |
| public void | setErrorLocale(Locale errorLocale)
Implements com. Sets the locale for all error messages. |
| public void | setField(Field field)
Implements com. Sets the field to be processed. |
| public final void | setFieldValue(Object bean, String value, String header)
Implements com. Populates the selected field of the bean. |
| public void | setRequired(boolean required)
Implements com. Determines whether or not a field is required. |
| public void | setType(Class<?> type)
Implements com. Sets the type of the bean this field is attached to. |
| private void | |
| public final String[] | write(Object bean, I index)
Implements com. This method takes the current value of the field in question in the bean passed in and converts it to a string. |
| converter | back to summary |
|---|---|
| protected CsvConverter converter A class that converts from a string to the destination type on reading and vice versa on writing. This is only used for opencsv-internal conversions, not by custom converters. | |
| errorLocale | back to summary |
|---|---|
| protected Locale errorLocale Locale for error messages. | |
| field | back to summary |
|---|---|
| protected Field field The field this class represents. | |
| fieldAccess | back to summary |
|---|---|
| protected FieldAccess<Object> fieldAccess An encapsulated way of accessing the member variable associated with this field. | |
| required | back to summary |
|---|---|
| protected boolean required Whether or not this field is required. | |
| type | back to summary |
|---|---|
| protected Class<?> type The type the field is located in. This is not necessarily the declaring class in the case of inheritance, but rather the type that opencsv expects to instantiate. | |
| AbstractBeanField | back to summary |
|---|---|
| public AbstractBeanField() Default nullary constructor, so derived classes aren't forced to create a constructor identical to this one. | |
| AbstractBeanField | back to summary |
|---|---|
public AbstractBeanField(Class<?> type, Field field, boolean required, Locale errorLocale, CsvConverter converter)
| |
| assignValueToField | back to summary |
|---|---|
| protected void assignValueToField(Object bean, Object obj, String header) throws CsvDataTypeMismatchException Assigns the given object to this field of the destination bean. Uses the setter method if available. Derived classes can override this method if they have special needs for setting the value of a field, such as adding to an existing collection.
| |
| convert | back to summary |
|---|---|
| protected abstract Object convert(String value) throws CsvDataTypeMismatchException, CsvConstraintViolationException Method for converting from a string to the proper datatype of the destination field. This method must be specified in all non-abstract derived classes.
| |
| convertToWrite | back to summary |
|---|---|
| protected String convertToWrite(Object value) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException This is the method that actually performs the conversion from field to
string for The default implementation simply calls
| |
| getErrorLocale | back to summary |
|---|---|
| public Locale getErrorLocale() Implements com. Doc from com. Returns the error locale for the beans. Used by the opencsv provided validators to populate the error messages they generate.
| |
| getField | back to summary |
|---|---|
| public Field getField() Implements com. Doc from com. Gets the field to be processed.
| |
| getFieldValue | back to summary |
|---|---|
| public Object getFieldValue(Object bean) Implements com. Doc from com. Gets the contents of the selected field of the given bean. This method performs no conversions of any kind, but simply gets the value of the desired field using an accessor method if one is available and reflection if one is not.
| |
| getType | back to summary |
|---|---|
| public Class Implements com. Doc from com. Gets the type of the bean this field is attached to. This is necessary because the declaring class as given by the field itself may be a superclass of the class that is instantiated during bean population.
| |
| indexAndSplitMultivaluedField | back to summary |
|---|---|
| public Object[] indexAndSplitMultivaluedField(Object value, I index) throws CsvDataTypeMismatchException Implements com. Doc from com. Given the value of a bean field and an index into that value, determine what values need to be written. When writing a bean to a CSV file, some single fields from the bean could have values that need to be split into multiple fields when writing them to the CSV file. Given the value of the bean field and an index into the data, this method returns the objects to be converted and written.
| |
| isFieldEmptyForWrite | back to summary |
|---|---|
| protected boolean isFieldEmptyForWrite(Object value) Whether or not this implementation of This allows any overriding class to define "empty" while writing
values to a CSV file in a way that is meaningful for its own data. A
simple example is a The default implementation simply checks for
| |
| isRequired | back to summary |
|---|---|
| public boolean isRequired() Implements com. Doc from com. Answers the query, whether this field is required or not.
| |
| preProcessValue | back to summary |
|---|---|
| private String preProcessValue(PreAssignmentProcessor processor, String value) throws CsvValidationException | |
| setErrorLocale | back to summary |
|---|---|
| public void setErrorLocale(Locale errorLocale) Implements com. Doc from com. Sets the locale for all error messages.
| |
| setField | back to summary |
|---|---|
| public void setField(Field field) Implements com. Doc from com. Sets the field to be processed.
| |
| setFieldValue | back to summary |
|---|---|
| public final void setFieldValue(Object bean, String value, String header) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException, CsvConstraintViolationException, CsvValidationException Implements com. Doc from com. Populates the selected field of the bean. This method performs conversion on the input string and assigns the result to the proper field in the provided bean.
| |
| setRequired | back to summary |
|---|---|
| public void setRequired(boolean required) Implements com. Doc from com. Determines whether or not a field is required. Implementation Note This method is necessary for custom converters. If we did not have it, every custom converter would be required to implement a constructor with this one boolean parameter, and the instantiation code for the custom converter would look much uglier.
| |
| setType | back to summary |
|---|---|
| public void setType(Class<?> type) Implements com. Doc from com. Sets the type of the bean this field is attached to.
| |
| validateValue | back to summary |
|---|---|
| private void validateValue(PreAssignmentValidator validator, String value) throws CsvValidationException | |
| write | back to summary |
|---|---|
| public final String[] write(Object bean, I index) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException Implements com. This method takes the current value of the field in question in the bean
passed in and converts it to a string.
It is actually a stub that calls
| |