Class UncheckedCsvToXml

  • All Implemented Interfaces:
    AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, MessageEventGenerator, Service, StateManagedComponent

    @ComponentProfile(summary="Easily transform a document from CSV to XML",
                      tag="service,transform,csv,xml",
                      since="3.11.0")
    public class UncheckedCsvToXml
    extends CsvToXmlServiceImpl
    Unchecked CSV to XML using net.sf.supercsv:super-csv.

    This service does not attempt to make parsing decisions, so CSV files that have differing number of columns on each line would be perfectly acceptable.

    For example, given an input document :

     
     HEADER,19052017
     PRODUCT-CODE,BARCODE,DP,PROMPRICE,DISCOUNT,INSTOCK,REPORT,REPORT-DATE,SOURCE
     XXXXXXXX,1234567890123,2.75,0.00,5.00,2,,,GSL
     TRAILER,4
       
     
    Then the output would be
     
      <csv-xml>
       <record>
          <csv-field-1>HEADER<csv-field-1>
          <csv-field-2>19052017</csv-field-2>
       </record>
       <record>
          <csv-field-1>PRODUCT-CODE<csv-field-1>
          <csv-field-2>BARCODE</csv-field-2>
          <csv-field-3>DP</csv-field-3>
          <csv-field-4>PROMPRICE</csv-field-4>
          <csv-field-5>DISCOUNT</csv-field-5>
          <csv-field-6>INSTOCK</csv-field-6>
          <csv-field-7>REPORT</csv-field-7>
          <csv-field-8>REPORT-DATE</csv-field-8>
          <csv-field-9>SOURCE</csv-field-9>
       </record>
       <record>
          <csv-field-1>XXXXXXXX<csv-field-1>
          <csv-field-2>1234567890123</csv-field-2>
          <csv-field-3>,2.75</csv-field-3>
          <csv-field-4>0.00</csv-field-4>
          <csv-field-5>5.00</csv-field-5>
          <csv-field-6>2</csv-field-6>
          <csv-field-7></csv-field-7>
          <csv-field-8></csv-field-8>
          <csv-field-9>GSL</csv-field-9>
       </record>
       <record>
          <csv-field-1>TRAILER<csv-field-1>
          <csv-field-2>4</csv-field-2>
       </record>
      </csv-xml>
     
     

    Because there is no verification that the CSV columns matchup; if the message type isn't a CSV (e.g. it's JSON or XML), then it will still be marked up into XML, so take that into account when using this as part of a workflow. Behaviour with rogue messages may not be as you expect.

    In the adapter configuration file this class is aliased as unchecked-csv-to-xml-transform which is the preferred alternative to the fully qualified classname when building your configuration.