You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Tim Dudgeon <td...@gmail.com> on 2012/10/02 17:04:55 UTC

Reading CSV as Map not List

Is it possible to use the CSV component to read a CSV file and return a 
List<Map<String,String>>?
The keys being the values in the first line of the file.
I can only see a way to get it to generate a List<List<String>>.

Thanks
Tim

Re: Reading CSV as Map not List

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Oct 2, 2012 at 5:04 PM, Tim Dudgeon <td...@gmail.com> wrote:
> Is it possible to use the CSV component to read a CSV file and return a
> List<Map<String,String>>?
> The keys being the values in the first line of the file.
> I can only see a way to get it to generate a List<List<String>>.
>

No.


> Thanks
> Tim



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Reading CSV as Map not List

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Oct 2, 2012 at 8:20 PM, Tim Dudgeon <td...@gmail.com> wrote:
> On 02/10/2012 19:07, Christian Müller wrote:
>>
>> That would be a incompatible change. And what if the user don't want to
>> specify the keys?
>
> I was more asking if there was an option to allow this, not asking for a
> change in behaviour.
> Would be useful e.g. if the data was to be inserted into a database using
> SQL, where the keys were the column names.
> I think it could somehow be done with a custom Aggregator, but hoping there
> was already a solution.
>

Maybe an option could be added, to enrich the message with a header
that has the header columns as a List<String>.
Then you can use that to mimic a map, as you got the headers and the data.

That said, another option could be added to use List<Map> structure
instead. A LinkedHashMap should be used to ensure the ordering of the
map would be as a List.

We love contributions. So patches with unit tests is welcome.
http://camel.apache.org/contributing.html


>
>>
>> Do you have an issue with the current implementation?
>
> Not at all. Just doesn't support my use case ;-)
>
> Tim
>
>>
>> Best,
>> Christian
>>
>> Sent from a mobile device
>> Am 02.10.2012 17:05 schrieb "Tim Dudgeon" <td...@gmail.com>:
>>
>>> Is it possible to use the CSV component to read a CSV file and return a
>>> List<Map<String,String>>?
>>> The keys being the values in the first line of the file.
>>> I can only see a way to get it to generate a List<List<String>>.
>>>
>>> Thanks
>>> Tim
>>>
>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Reading CSV as Map not List

Posted by Tim Dudgeon <td...@gmail.com>.
On 02/10/2012 19:07, Christian Müller wrote:
> That would be a incompatible change. And what if the user don't want to
> specify the keys?
I was more asking if there was an option to allow this, not asking for a 
change in behaviour.
Would be useful e.g. if the data was to be inserted into a database 
using SQL, where the keys were the column names.
I think it could somehow be done with a custom Aggregator, but hoping 
there was already a solution.

>
> Do you have an issue with the current implementation?
Not at all. Just doesn't support my use case ;-)

Tim
>
> Best,
> Christian
>
> Sent from a mobile device
> Am 02.10.2012 17:05 schrieb "Tim Dudgeon" <td...@gmail.com>:
>
>> Is it possible to use the CSV component to read a CSV file and return a
>> List<Map<String,String>>?
>> The keys being the values in the first line of the file.
>> I can only see a way to get it to generate a List<List<String>>.
>>
>> Thanks
>> Tim
>>


Re: Reading CSV as Map not List

Posted by Christian Müller <ch...@gmail.com>.
That would be a incompatible change. And what if the user don't want to
specify the keys?

Do you have an issue with the current implementation?

Best,
Christian

Sent from a mobile device
Am 02.10.2012 17:05 schrieb "Tim Dudgeon" <td...@gmail.com>:

> Is it possible to use the CSV component to read a CSV file and return a
> List<Map<String,String>>?
> The keys being the values in the first line of the file.
> I can only see a way to get it to generate a List<List<String>>.
>
> Thanks
> Tim
>