Convert bundle for dropwizard.It manages file importing and exporting between formats(xls, xlsx, xml, csv, tsv, json) to POJOs with the help of annotations. Annotations prevents the developer to write extra code for validating the procedure.
Creating a basic system for different libraries. Helping user to do the most important importing and exporting operations with one annotation.
You have to complete 3 steps in order to start using robe-convert bundle.
- Add dependency (Maven sample)
<dependency>
<groupId>io.robe</groupId>
<artifactId>robe-convert</artifactId>
<version>0.5.0</version>
</dependency>
- Use
@Convert
annotation to makes you . Sample:
public class SamplePojo {
@Convert(order = 0, unique = true, title = "User Id")
private int id;
@Convert(order = 0)
private String name;
...
Now it is ready for import&export operations with all formats below.
- User importer or exporter to complete the operation.
CSVImporter<SamplePojo> importer = new CSVImporter<>(SamplePojo.class);
List<SamplePojo> list = importer.importStream(new FileInputStream(outputFile.getPath()));
!!! You can look at the test classes for sample usage !!!
Usage and details will be explained below.
- xls : Apache POI
- xlsx: Apache POI
- json: Jackson
- xml : Jackson (Different configuration)
- csv : SuperCSV
- tsv : SuperCSV
Please look at the test classes for sample usage. If you really want to see a quick demo ...
CSVExporter<SamplePojo> exporter = new CSVExporter(SamplePojo.class);
exporter.exportStream(outputStream, TestData.getData().iterator());
CSVImporter<SamplePojo> importer = new CSVImporter<>(SamplePojo.class);
List<SamplePojo> list = importer.importStream(new FileInputStream(outputFile.getPath()));
XLSExporter<SamplePojo> xlsExporter = new XLSExporter(SamplePojo.class, false);
xlsExporter.exportStream(outputStream, TestData.getData().iterator());
XLSImporter<SamplePojo> xlsImporter = new XLSImporter(SamplePojo.class, false);
List<SamplePojo> list = xlsImporter.importStream(new FileInputStream(outputFile.getPath()));