简体   繁体   中英

Using Mule Dataweave to import CSV?

My solution involves importing various CSV files and converting them to Java map structures, and I've been using a DataMapper transformer for this to great success -- that is, until I hit the test server. Although we have an Enterprise installation, we don't have the now-no-longer-built-it DataMapper plugin, so I'm looking into rewriting my importers using the Transform Message component (what Mule Soft also refer to as "dataweave").

Alas! There are plenty of examples and tutorials on using the DataMapper transformer (to read CSV files), and there are plenty of examples and tutorials on using the Transform Message component (to write CSV files), but I cannot for the life of me find any description of how to read a CSV file with a Transform Message component. It seems that all examples deal with xml input.

Help!

How should I configure the "Context" (input) pane of the Transform Message component, and how should the transformation look to output a Java map structure? For argument's sake, lets just say my CSV file format is a simple "ID,NAME,NUMBER" and does include a header row.

Naturally, we are in a great hurry to get this issue resolved, so any help would be much appreciated.

If you only want to output a java array of maps from a CSV input, you just need to do this:

%dw 1.0
%output application/java
---
payload

Also make sure the mime-type of your payload is set to application/csv.

If it's not, you can alternatively put <dw:input-payload mimeType="application/csv"/> inside your transform-message

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM