Interface BeanField<T,​I>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.Locale getErrorLocale()
      Returns the error locale for the beans.
      java.lang.reflect.Field getField()
      Gets the field to be processed.
      java.lang.Object getFieldValue​(java.lang.Object bean)
      Gets the contents of the selected field of the given bean.
      java.lang.Class<?> getType()
      Gets the type of the bean this field is attached to.
      java.lang.Object[] indexAndSplitMultivaluedField​(java.lang.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​(java.util.Locale errorLocale)
      Sets the locale for all error messages.
      void setField​(java.lang.reflect.Field field)
      Sets the field to be processed.
      void setFieldValue​(java.lang.Object bean, java.lang.String value, java.lang.String header)
      Populates the selected field of the bean.
      void setRequired​(boolean required)
      Determines whether or not a field is required.
      void setType​(java.lang.Class<?> type)
      Sets the type of the bean this field is attached to.
      java.lang.String[] write​(java.lang.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.
    • Method Detail

      • getType

        java.lang.Class<?> getType()
        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.
        Returns:
        The type of the bean this field is attached to
        Since:
        5.0
      • setType

        void setType​(java.lang.Class<?> type)
        Sets the type of the bean this field is attached to.
        Parameters:
        type - The type that is instantiated when this field is used
        Since:
        5.0
      • setField

        void setField​(java.lang.reflect.Field field)
        Sets the field to be processed.
        Parameters:
        field - Which field is being populated
      • getField

        java.lang.reflect.Field getField()
        Gets the field to be processed.
        Returns:
        A field object
        See Also:
        Field
      • isRequired

        boolean isRequired()
        Answers the query, whether this field is required or not.
        Returns:
        True if the field is required to be set (cannot be null or an empty string), false otherwise
        Since:
        3.10
      • setRequired

        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.
        Parameters:
        required - Whether or not the field is required
        Since:
        3.10
      • getFieldValue

        java.lang.Object getFieldValue​(java.lang.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.
        Parameters:
        bean - Object containing the field to be read
        Returns:
        The value of the field in the given bean
        Since:
        4.2
      • indexAndSplitMultivaluedField

        java.lang.Object[] indexAndSplitMultivaluedField​(java.lang.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.
        Parameters:
        value - The value of the bean field that should be written
        index - 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.
        Returns:
        An array of Objects that should be converted for the output and written
        Throws:
        CsvDataTypeMismatchException - If value is not of the type expected by the implementing class
        Since:
        4.2
      • write

        java.lang.String[] write​(java.lang.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.
        Parameters:
        bean - The bean holding the field to be written
        index - 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.
        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, but 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.
        Throws:
        CsvDataTypeMismatchException - If expected to convert an unsupported data type
        CsvRequiredFieldEmptyException - If the field is marked as required, but is currently empty
        Since:
        3.9
      • setErrorLocale

        void setErrorLocale​(java.util.Locale errorLocale)
        Sets the locale for all error messages.
        Parameters:
        errorLocale - Locale for error messages. If null, the default locale is used.
        Since:
        4.0
      • getErrorLocale

        java.util.Locale getErrorLocale()
        Returns the error locale for the beans. Used by the opencsv provided validators to populate the error messages they generate.
        Returns:
        Locale for error messages.
        Since:
        5.0