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?
If you want an alternative, use Open CSV CSVWriter
:
public CSVWriter(Writer writer, char separator)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With