Class StatefulBeanToCsvBuilder<T>

  • Type Parameters:
    T - The type of the beans being written

    public class StatefulBeanToCsvBuilder<T>
    extends java.lang.Object
    This is a builder for StatefulBeanToCsv, allowing one to set all parameters necessary for writing a CSV file.
    Since:
    3.9
    Author:
    Andrew Rucker Jones
    • Constructor Detail

      • StatefulBeanToCsvBuilder

        public StatefulBeanToCsvBuilder​(java.io.Writer writer)
        Default constructor - Being stateful the writer is required by the builder at the start and not added in later.
        Parameters:
        writer - - the writer that will be used to output the csv version of the bean.
      • StatefulBeanToCsvBuilder

        public StatefulBeanToCsvBuilder​(ICSVWriter icsvWriter)
        Being stateful the writer is required by the builder at the start and not added in later. By passing in the ICSVWriter you can create a writer with the desired ICSVParser to allow you to use the exact same parser for reading and writing.
        Parameters:
        icsvWriter - - the ICSVWriter that will be used to output the csv version of the bean.
        Since:
        4.2
    • Method Detail

      • withMappingStrategy

        public StatefulBeanToCsvBuilder<T> withMappingStrategy​(MappingStrategy<T> mappingStrategy)
        Sets the mapping strategy for writing beans to a CSV destination.

        If the mapping strategy is set this way, it will always be used instead of automatic determination of an appropriate mapping strategy.

        It is perfectly legitimate to read a CSV source, take the mapping strategy from the read operation, and pass it in to this method for a write operation. This conserves some processing time, but, more importantly, preserves header ordering.

        Parameters:
        mappingStrategy - The mapping strategy to be used for write operations
        Returns:
        this
      • withOrderedResults

        public StatefulBeanToCsvBuilder<T> withOrderedResults​(boolean orderedResults)
        Sets whether or not results must be written in the same order in which they appear in the list of beans provided as input.
        Parameters:
        orderedResults - Whether or not the lines written are in the same order they appeared in the input
        Returns:
        this
        Since:
        4.0
        See Also:
        StatefulBeanToCsv.setOrderedResults(boolean)
      • withIgnoreField

        public StatefulBeanToCsvBuilder<T> withIgnoreField​(java.lang.Class<?> type,
                                                           java.lang.reflect.Field field)
                                                    throws java.lang.IllegalArgumentException
        Adds a Field to the list of fields opencsv should ignore completely.

        May be called as many times as necessary.

        Parameters:
        type - The class opencsv will encounter the field in during processing. In the case of inheritance, this may not be the declaring class.
        field - The field opencsv is to ignore
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - If one of the parameters is null or field cannot be found in type.
        Since:
        5.0
        See Also:
        MappingStrategy.ignoreFields(MultiValuedMap)
      • build

        public StatefulBeanToCsv<T> build()
        Builds a StatefulBeanToCsv from the information provided, filling in default values where none have been specified.
        Returns:
        A new StatefulBeanToCsv