Skip to content

marshallers

Mahmoud Ben Hassine edited this page Feb 7, 2020 · 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 easy-batch-flatfile StringRecord marshals a POJO to CSV format
FixedLengthRecordMarshaller easy-batch-flatfile StringRecord marshals a POJO to fixed-length format
UnivocityFixedWidthRecordMarshaller easy-batch-univocity StringRecord marshals a POJO to fixed-width format using Univocity
ApacheCommonCsvRecordMarshaller easy-batch-apache-common-csv StringRecord marshals a POJO to CSV format using Apache commons CSV
UnivocityCsvRecordMarshaller easy-batch-univocity StringRecord marshals a POJO to CSV format using Univocity
UnivocityTsvRecordMarshaller easy-batch-univocity StringRecord marshals a POJO to TSV format using Univocity
XmlRecordMarshaller easy-batch-xml XmlRecord marshals a POJO annotated with javax.xml.bind.annotation.XmlRootElement to Xml format using Jaxb
JsonRecordMarshaller easy-batch-json JsonRecord marshals a POJO to Json format using JsonB
XstreamRecordMarshaller easy-batch-xstream XmlRecord marshals a POJO to Xml format using XStream
GsonRecordMarshaller easy-batch-gson JsonRecord marshals a POJO to Json format using Gson
JacksonRecordMarshaller easy-batch-jackson JsonRecord marshals a POJO to Json format using Jackson
YamlRecordMarshaller easy-batch-yaml YamlRecord marshals a POJO to Yaml format using yamlbeans
MsExcelRecordMarshaller easy-batch-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. It is also possible to use the BeanFieldExtractor to format field by registering a custom TypeConverter<?, String>.

Clone this wiki locally