You can try using <unmarshal> <bindy packages="org.fusesource.camel" type="Csv" />. </unmarshal>
Thanks RG -----Original Message----- From: Claus Ibsen [mailto:[email protected]] Sent: Thursday, September 11, 2014 11:10 AM To: [email protected] Subject: Re: CSV Parsing Hi You can also use the splitter eip On Thu, Sep 11, 2014 at 1:44 AM, Matt Raible <[email protected]> wrote: > I have a String that's delimited by ~. This string is returned from a > database query. I'm able to parse it with the following code in my route: > > @Override > public void configure() throws Exception { > CsvDataFormat csv = new CsvDataFormat(); > csv.setDelimiter("~"); > ... > > .to("bean:myStoredProcedure") > > .process(myJdbcProcessor) > > .unmarshal(csv) > > .process(mySearchCsvProcessor) > > Today, I encountered a use case where not one string would be returned, but > multiple strings. To handle this, I've changed myJdbcProcessor to have the > following: > > > List<String> results = jdbcTemplate.queryForList("...", String.class); > > if (results.size() == 1) { > exchange.getIn().setBody(results.get(0), String.class); > } else { > exchange.getIn().setBody(results, List.class); > } > > When the result size is 1, everything works as expected. However, when > there are multiple results, the csv unmarshal blows up with the following > error: > > org.apache.camel.InvalidPayloadException: No body available of type: > java.io.InputStream > > Is it possible to parse multiple lines with unmarshal(csv)? > > I tried the following, but that didn't work b/c it only gets the first line: > > exchange.getIn().setBody(StringUtils.collectionToCommaDelimitedString(results), > String.class); > > > Thanks, > > Matt -- Claus Ibsen ----------------- Red Hat, Inc. Email: [email protected] Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen hawtio: http://hawt.io/ fabric8: http://fabric8.io/
