Languages
[Edit]
EN

Java - how to write java object to CSV file using Jackson CSV library

1 points
Created by:
Yusef-Ewing
479

1. Overview

Edit

In this post we will save java object into CSV file using Jackson CSV processor.

To use Jackson CSV library we need to add jackson-dataformat-csv dependency to pom.xml.

2. Write java object to CSV file

Edit

Below we have 2 classes we need to save simple UserDto java class to CSV file.
Ensure to set correct path and filename as output.

To run this example copy to your project those 2 files:

  1. UserCsvWriter
  2. UserDto

2.1 Logic

Logic which saves UserDto java pojo object to CSV file with Jackson CSV library.

Usage of classes:

  • CsvMapper + CsvSchema from jackson CSV library
  • ObjectWriter from jackson databind library
  • JsonGenerator from jackson core

Output:

2.2 User Pojo object - UserDto

References

Edit
  1. jackson-dataformat-csv - maven
  2. Comma-separated values (CSV) - wiki
  3. CsvMapper - JavaDoc
  4. CsvSchema - JavaDoc
  5. ObjectWriter - JavaDoc
  6. JsonGenerator - JavaDoc
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join