Skip to content

marshallers

Mahmoud Ben Hassine edited this page Jun 4, 2017 · 2 revisions

A RecordMarshaller does the opposite task of a RecordMapper: it marshals the payload of a record (typically a POJO) to a target format (Xml, Json, Yaml, Csv, etc).

Here is a table of built-in marshallers and how to use them:

Marshaller Module Record type Description
DelimitedRecordMarshaller easybatch-flatfile StringRecord marshals a POJO to CSV format
FixedLengthRecordMarshaller easybatch-flatfile StringRecord marshals a POJO to fixed-length format
UnivocityFixedWidthRecordMarshaller easybatch-univocity StringRecord marshals a POJO to fixed-width format using Univocity
ApacheCommonCsvRecordMarshaller easybatch-apache-common-csv StringRecord marshals a POJO to CSV format using Apache commons CSV
UnivocityCsvRecordMarshaller easybatch-univocity StringRecord marshals a POJO to CSV format using Univocity
UnivocityTsvRecordMarshaller easybatch-univocity StringRecord marshals a POJO to TSV format using Univocity
XmlRecordMarshaller easybatch-xml XmlRecord marshals a POJO annotated with javax.xml.bind.annotation.XmlRootElement to Xml format using Jaxb
XstreamRecordMarshaller easybatch-xstream XmlRecord marshals a POJO to Xml format using XStream
GsonRecordMarshaller easybatch-gson JsonRecord marshals a POJO to Json format using Gson
JacksonRecordMarshaller easybatch-jackson JsonRecord marshals a POJO to Json format using Jackson
YamlRecordMarshaller easybatch-yaml YamlRecord marshals a POJO to Yaml format using yamlbeans
MongoDBRecordMarshaller easybatch-mongodb MongoDBRecord marshals a POJO to a Mongo DBObject instance using Morphia
MsExcelRecordMarshaller easybatch-msexcel MsExcelRecord marshals a POJO to MsExcel row using Apache POI

Record marshalling considerations

By default, the DelimitedRecordMarshaller, FixedLengthRecordMarshaller, OpenCsvRecordMarshaller and ApacheCommonCsvRecordMarshaller do not support recursive (deep) marshalling of POJOs.

Custom field extraction

In order to have more control over how to extract and format your domain object's fields, you can implement the FieldExtractor interface and supply your implementation at marshaller's construction time. Easy Batch provides the BeanFieldExtractor that uses Java Bean conventions to extract field from a POJO.

Clone this wiki locally