You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by contactreji <co...@gmail.com> on 2014/04/17 08:00:54 UTC
Camel Bindy - Issues with returntype
Hi
I am trying to parse some CSV data. Camel Bindy component seems to be doing
its job well.
When I am taking the data to a processor to access each Object separately
and do the processing, I see that Bindy returns a List and the List
contains a Hashmap!!
Is there a way to configure Bindy to return a list of Java Objects instead
of Hashmap?
I did a debug and the screenshot attached. In the debug view, we see that
exchange->in contains a HashMap.
Can you suggest how can i retrieve the data? If its HashMap, what would be
the keys to retrieve the value?
<http://camel.465427.n5.nabble.com/file/n5750340/Bindy.jpg>
My Camel Code is
*
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">
<bean id="bindyDataformat"
class="org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat">
<constructor-arg value="com.poc.camel.csv.java.bindy" />
</bean>
<bean id="csv" class="com.poc.camel.csv.java.bindy.HandleOrderBean" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<dataFormats>
<jaxb id="myJaxb" prettyPrint="true"
contextPath="com.poc.camel.csv.java.bindy" />
</dataFormats>
<route streamCache="true">
<from uri="file://C:/Users/Mathews/Desktop/in" />
<unmarshal ref="bindyDataformat" />
<to uri="bean:csv" />
</route>
<route>
<from uri="seda:queue:in" />
<to uri="log:reached route 2"/>
<marshal ref="myJaxb" />
<to uri="file://C:/Users/Mathews/Desktop/out" />
</route>
</camelContext>
</beans>
*
And Java code is
*
package com.poc.camel.csv.java.bindy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class HandleOrderBean implements Processor {
@SuppressWarnings("unchecked")
@Override
public void process(Exchange exchange) throws Exception {
// TODO Auto-generated method stub
List list=new ArrayList<Result>();
list = (List) exchange.getIn().getBody();
System.out.println("Wanna convert things into XML now");
System.out.println("Wanna convert things into XML now");
/*list.toString();*/
}
}
*
and My POJO class is
package com.poc.camel.csv.java.bindy;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
import org.apache.camel.dataformat.bindy.annotation.DataField;
@XmlRootElement
@CsvRecord(separator = ",",crlf="WINDOWS",generateHeaderColumns=false)
public class Result implements Serializable{
@DataField(pos = 1)
private String firstName;
@DataField(pos = 2)
private String lastName;
@DataField(pos = 3)
private String rollNo;
@DataField(pos = 4)
private String result;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getRollNo() {
return rollNo;
}
public void setRollNo(String rollNo) {
this.rollNo = rollNo;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Bindy-Issues-with-returntype-tp5750340.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Bindy - Issues with returntype
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Bindy does not support mapping to java.util.Map. The idea is that you
may from flatfile/csv to POJOs, where you annotate the POJOs with how
to map.
Maybe take a look at some of the other csv components/data formats,
such as beanio, csv, flatpack
You can see the list here
http://camel.apache.org/data-format.html
On Wed, Apr 16, 2014 at 11:00 PM, contactreji <co...@gmail.com> wrote:
> Hi
>
> I am trying to parse some CSV data. Camel Bindy component seems to be doing
> its job well.
> When I am taking the data to a processor to access each Object separately
> and do the processing, I see that Bindy returns a List and the List
> contains a Hashmap!!
>
> Is there a way to configure Bindy to return a list of Java Objects instead
> of Hashmap?
>
> I did a debug and the screenshot attached. In the debug view, we see that
> exchange->in contains a HashMap.
>
> Can you suggest how can i retrieve the data? If its HashMap, what would be
> the keys to retrieve the value?
>
> <http://camel.465427.n5.nabble.com/file/n5750340/Bindy.jpg>
>
>
>
> My Camel Code is
>
> *
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:amq="http://activemq.apache.org/schema/core"
> xsi:schemaLocation="
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
> http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd
> http://activemq.apache.org/schema/core
> http://activemq.apache.org/schema/core/activemq-core.xsd">
>
>
>
> <bean id="bindyDataformat"
> class="org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat">
> <constructor-arg value="com.poc.camel.csv.java.bindy" />
> </bean>
>
> <bean id="csv" class="com.poc.camel.csv.java.bindy.HandleOrderBean" />
>
> <camelContext xmlns="http://camel.apache.org/schema/spring">
>
> <dataFormats>
> <jaxb id="myJaxb" prettyPrint="true"
> contextPath="com.poc.camel.csv.java.bindy" />
> </dataFormats>
>
>
>
> <route streamCache="true">
> <from uri="file://C:/Users/Mathews/Desktop/in" />
> <unmarshal ref="bindyDataformat" />
> <to uri="bean:csv" />
>
> </route>
>
> <route>
> <from uri="seda:queue:in" />
> <to uri="log:reached route 2"/>
> <marshal ref="myJaxb" />
> <to uri="file://C:/Users/Mathews/Desktop/out" />
> </route>
>
> </camelContext>
>
> </beans>
>
>
> *
>
>
> And Java code is
>
> *
> package com.poc.camel.csv.java.bindy;
>
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.List;
> import java.util.Map;
>
> import org.apache.camel.Exchange;
> import org.apache.camel.Processor;
>
> public class HandleOrderBean implements Processor {
>
>
> @SuppressWarnings("unchecked")
> @Override
> public void process(Exchange exchange) throws Exception {
> // TODO Auto-generated method stub
>
> List list=new ArrayList<Result>();
>
>
> list = (List) exchange.getIn().getBody();
>
>
> System.out.println("Wanna convert things into XML now");
>
> System.out.println("Wanna convert things into XML now");
> /*list.toString();*/
>
> }
>
>
>
>
> }
>
>
> *
>
>
> and My POJO class is
>
> package com.poc.camel.csv.java.bindy;
>
> import java.io.Serializable;
>
> import javax.xml.bind.annotation.XmlRootElement;
> import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
> import org.apache.camel.dataformat.bindy.annotation.DataField;
>
> @XmlRootElement
> @CsvRecord(separator = ",",crlf="WINDOWS",generateHeaderColumns=false)
> public class Result implements Serializable{
>
> @DataField(pos = 1)
> private String firstName;
>
> @DataField(pos = 2)
> private String lastName;
>
> @DataField(pos = 3)
> private String rollNo;
>
> @DataField(pos = 4)
> private String result;
>
> public String getFirstName() {
> return firstName;
> }
>
> public void setFirstName(String firstName) {
> this.firstName = firstName;
> }
>
> public String getLastName() {
> return lastName;
> }
>
> public void setLastName(String lastName) {
> this.lastName = lastName;
> }
>
> public String getRollNo() {
> return rollNo;
> }
>
> public void setRollNo(String rollNo) {
> this.rollNo = rollNo;
> }
>
> public String getResult() {
> return result;
> }
>
> public void setResult(String result) {
> this.result = result;
> }
>
>
>
> }
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Bindy-Issues-with-returntype-tp5750340.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/