Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jackson csv writer doesn't use correct column separator

Tags:

java

jackson

I'm trying to write a CSV file using Jackson 2.2.2 (especially jackson-dataformat-csv) but i can't get it to use the ';' as fileseparator.

i'm using the following code to initialize the writer:

CsvMapper mapper = new CsvMapper();
CsvSchema schema = mapper.schemaFor(MyObject.class);
schema = schema.withColumnSeparator(CSV_COLUMN_SEPARATOR);

ObjectWriter myObjectWriter = mapper.writer(schema);

To create the csv i do something like the following:

FileOutputStream tempFileOutputStream = new FileOutputStream(tempFile);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(tempFileOutputStream, STREAM_BUFFER_SIZE);
writerOutputStream = new OutputStreamWriter(bufferedOutputStream, FILE_ENCODING);

myObjectWriter.writeValue(writerOutputStream, listOfMyObjects);

However the resulting file still uses the default ',' as column separator. When i check the object with the debugger the ';' is set as separator in the object so i guess it should work. Does anyone know what i'm doing wrong or is this a bug?

like image 437
Ozzie Avatar asked Nov 01 '22 15:11

Ozzie


1 Answers

If you want an alternative, use Open CSV CSVWriter:

public CSVWriter(Writer writer, char separator)
like image 113
Benoit Wickramarachi Avatar answered Nov 08 '22 07:11

Benoit Wickramarachi