Example usage for com.fasterxml.jackson.dataformat.csv CsvSchema withoutHeader

List of usage examples for com.fasterxml.jackson.dataformat.csv CsvSchema withoutHeader

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.csv CsvSchema withoutHeader.

Prototype

public CsvSchema withoutHeader() 

Source Link

Document

Helper method for construcing and returning schema instance that is similar to this one, except that it will not be using header line.

Usage

From source file:org.jberet.support.io.JacksonCsvItemReaderWriterBase.java

protected CsvSchema buildCsvSchema(CsvSchema schema) throws Exception {
    if (schema == null) {
        columns = columns.trim();/*from  ww  w .  j av a 2  s .c  om*/
        if (columns.indexOf(',') < 0 && columns.indexOf(' ') < 0) {
            //no comma and no space, assume it's java class name for schema
            schema = csvMapper.schemaFor(getClass().getClassLoader().loadClass(columns));
        } else {
            //manually build CsvSchema
            final String[] cols = columns.split(",");
            final CsvSchema.Builder builder = new CsvSchema.Builder();
            for (String e : cols) {
                e = e.trim();
                final int lastSpace = e.lastIndexOf(' ');
                if (lastSpace > 0) {
                    final String e1 = e.substring(0, lastSpace).trim();
                    final String e2 = e.substring(lastSpace + 1);
                    builder.addColumn(e1, CsvSchema.ColumnType.valueOf(e2));
                } else {
                    builder.addColumn(e);
                }
            }
            schema = builder.build();
        }
    }

    schema = useHeader ? schema.withHeader() : schema.withoutHeader();

    if (columnSeparator != null) {
        schema = schema.withColumnSeparator(columnSeparator.charAt(0));
    }
    if (quoteChar != null) {
        schema = schema.withQuoteChar(quoteChar.charAt(0));
    }
    if (nullValue != null) {
        schema = schema.withNullValue(nullValue);
    }

    //to allow comments like "# this is comments".
    //comments can be enabled or disabled with com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_YAML_COMMENTS
    //which corresponds to batch property jsonParserFeatures
    return schema.withComments();
}