java.lang.reflect.Field class to include
functionality that opencsv requires.
This includes a required flag and a
write(java. 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 |
|---|---|
| public Locale | |
| public Field | |
| public Object | Returns: The value of the field in the given beanObject containing the field to be read bean)Gets the contents of the selected field of the given bean. |
| public Class | Returns: The type of the bean this field is attached toGets the type of the bean this field is attached to. |
| public Object[] | Returns: An array ofObjects that should be converted for the
output and writtenThe value of the bean field that should be written value, I An index into index)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.Given the value of a bean field and an index into that value, determine what values need to be written. |
| public boolean | Returns: True if the field is required to be set (cannot be null or an empty string), false otherwiseAnswers the query, whether this field is required or not. |
| public void | setErrorLocale(Locale
Locale for error messages. If null, the default locale
is used. errorLocale)Sets the locale for all error messages. |
| public void | |
| public void | setFieldValue(Object
Object containing the field to be set. bean, String String containing the value to set the field to. value, String The header from the CSV file under which this value was found. header)Populates the selected field of the bean. |
| public void | setRequired(boolean
Whether or not the field is required required)Determines whether or not a field is required. |
| public void | |
| public String[] | Returns: An array of string representations for the values of this field out of the bean passed in. Typically, there will be only one value, butcom. 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.The bean holding the field to be written bean, I 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. 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. |
| getErrorLocale | back to summary |
|---|---|
| public Locale getErrorLocale() 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() Gets the field to be processed.
| |
| getFieldValue | back to summary |
|---|---|
| public Object getFieldValue(Object bean) 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 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 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.
| |
| isRequired | back to summary |
|---|---|
| public boolean isRequired() Answers the query, whether this field is required or not.
| |
| setErrorLocale | back to summary |
|---|---|
| public void setErrorLocale(Locale errorLocale) Sets the locale for all error messages.
| |
| setField | back to summary |
|---|---|
| public void setField(Field field) Sets the field to be processed.
| |
| setFieldValue | back to summary |
|---|---|
| public void setFieldValue(Object bean, String value, String header) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException, CsvConstraintViolationException, CsvValidationException 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) 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) Sets the type of the bean this field is attached to.
| |
| write | back to summary |
|---|---|
| public String[] write(Object bean, I index) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException This method takes the current value of the field in question in the bean passed in and converts it to one or more strings. This method is used to write beans back out to a CSV file, and should ideally provide an accurate representation of the field such that it is round trip equivalent. That is to say, this method should write data out just as it would expect to read the data in.
| |