Fork me on GitHub

Yap4j by PolymathicCoder

Yap4j is an annotation-driven POJO-based one-liner CSV parsing library...
In other words, it has never been this easy!

Motivation

Yap4j (Yet Another Java Parser For Java) was born after I spent a long frastruting couple of days experimenting with library after library to accomplish the simple task of parsing a CSV (Comma Seaprated Value) file. I struggled with various libaries from Apache's Commons CSV, which claims to unify and provide a common and simple interface with contributions from Skife CSV, Open CSV, and Genjava CSV, to Super CSV, which is probably the most usable and documented of all. Like any programmer with some free bandwidth, I decided to write my own and open-source it with the hope that nobody would have to go through what I went through over the most trival of tasks.
Enjoy and Fork!

Features

Installation

Yap4j is available on Maven Central

For Maven users

Include the following dependency in your POM file:

<dependency>
    <groupId>com.polymathiccoder</groupId>
    <artifactId>yap4j</artifactId>
    <version>0.1.0</version>
</dependency>

Example

Object-CSV Mapping Annotations

Classes and Fields can be selectively decorated with annotations to override defaults in the spirit of the configuration by exception best practice.

@CsvFile

This is a class level annotation used on POJOs to be mapped to CSV files.

Attribute Description Required Default
fileName The name and path to the CSV file Yes N/A
delimiter Record delimiters in the CSV file No Comma ( , )
noHeader determines wether the CSV has a header line or not No False

@CsvField

This is a field-level annotation. There is no requiremet on any field using this annotation to have a public access modifier, or accessor/mutator methods. The mapping will work on private and protected fields with no special accommodation.

Attribute Description Required Default
header The name of the corresponding record header in the CSV file Only if the noHeader attribute of @CsvFile is false N/A
position The position of the corresponding record in the CSV file Only if the noHeader attribute of @CsvFile is true N/A
format Determines how certain temporal types are formated in the CSV record such as java.util.Date and org.joda.time.Period Only if the field to-be-mapped-to is temporal Empty String
optional Determines whether the field is optional in the CSV file or not No False
ignore Determines whether the mapping be ignored or not No False
defaultValue Determines the default value to be set if the record is empty in the CSV file Only if the field to-be-mapped-to is primitive Empty String

License

Apache License, Version 2.0

Authors

PolymathicCoder (abdelmonaim.remani@gmail.com)

Contact

Abdelmonaim Remani (abdelmonaim.remani@gmail.com)

Download

You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/PolymathicCoder/Yap4j