You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Dennis Holunder <de...@gmail.com> on 2018/03/07 11:08:56 UTC

csv data format with ordered maps

Hello,

I need a CSV record mapper which would use maps, but ordered ones,
because I need the name of the first header field. Current
implementation creates HashMaps, where the original order is lost.

I tried to implement my own CsvRecordConverter to produce ordered map,
but the interface is not public. This is not expected,
CsvDataFormat.setRecordConverter has a public setter accepting this
interface.

Any workarounds?

Den

Re: csv data format with ordered maps

Posted by Dennis Holunder <de...@gmail.com>.
Thx, In newer camel versions it is indeed public. Unfortunately, I
can't upgrade right now

2018-03-07 16:45 GMT+01:00 Claus Ibsen-2 [via Camel]
<ml...@n5.nabble.com>:
> Hi
>
> I logged a ticket and implemented this
> https://issues.apache.org/jira/browse/CAMEL-12332
>
> The CsvRecordConverter is a public interface from camel-csv. You can
> implement your own, and configure on the dataformat
>
> On Wed, Mar 7, 2018 at 4:26 PM, Dennis Holunder <[hidden email]> wrote:
>
>> But you could make CsvRecordConverter public, so I could implement the
>> mapper myself. Or you implement converting of CSVRecord to
>> LinkedHashMap, shouldn't be a big deal
>>
>> 2018-03-07 16:17 GMT+01:00 Claus Ibsen-2 [via Camel]
>> <[hidden email]>:
>>> Hi
>>>
>>> Ah okay that is unfortunately in the commons-csv implementation. You
>>> would need to report this to them.
>>>
>>> Sadly there is no way to get the mapping on CSVRecord so we can get
>>> the column headers (we could maybe do some reflection as workaround).
>>>
>>> On Wed, Mar 7, 2018 at 3:29 PM, Dennis Holunder <[hidden email]> wrote:
>>>
>>>> in camel-csv component
>>>> CsvRecordConverters.mapConverter().convertRecord(CSVRecord record)
>>>>
>>>> it calls CSVRecord.toMap() which returns HashMap but CSVRecord is in
>>>> org.apache.commons.csv
>>>>
>>>> would be great if you could change it.
>>>>
>>>>
>>>>
>>>>
>>>> 2018-03-07 13:13 GMT+01:00 Claus Ibsen-2 [via Camel]
>>>> <[hidden email]>:
>>>>> Hi
>>>>>
>>>>> Can you point to where it creates HashMap, maybe we can change that to
>>>>> LinkedHashMap.
>>>>>
>>>>> On Wed, Mar 7, 2018 at 12:08 PM, Dennis Holunder <[hidden email]>
>>>>> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I need a CSV record mapper which would use maps, but ordered ones,
>>>>>> because I need the name of the first header field. Current
>>>>>> implementation creates HashMaps, where the original order is lost.
>>>>>>
>>>>>> I tried to implement my own CsvRecordConverter to produce ordered map,
>>>>>> but the interface is not public. This is not expected,
>>>>>> CsvDataFormat.setRecordConverter has a public setter accepting this
>>>>>> interface.
>>>>>>
>>>>>> Any workarounds?
>>>>>>
>>>>>> Den
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Claus Ibsen
>>>>> -----------------
>>>>> http://davsclaus.com @davsclaus
>>>>> Camel in Action 2: https://www.manning.com/ibsen2
>>>>>
>>>>>
>>>>> ________________________________
>>>>> If you reply to this email, your message will be added to the
>>>>> discussion
>>>>> below:
>>>>>
>>>>>
>>>>> http://camel.465427.n5.nabble.com/csv-data-format-with-ordered-maps-tp5818212p5818215.html
>>>>> To unsubscribe from Camel, click here.
>>>>> NAML
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> http://davsclaus.com @davsclaus
>>> Camel in Action 2: https://www.manning.com/ibsen2
>>>
>>>
>>> ________________________________
>>> If you reply to this email, your message will be added to the discussion
>>> below:
>>>
>>> http://camel.465427.n5.nabble.com/csv-data-format-with-ordered-maps-tp5818212p5818245.html
>>> To unsubscribe from Camel, click here.
>>> NAML
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://camel.465427.n5.nabble.com/csv-data-format-with-ordered-maps-tp5818212p5818251.html
> To unsubscribe from Camel, click here.
> NAML

Re: csv data format with ordered maps

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I logged a ticket and implemented this
https://issues.apache.org/jira/browse/CAMEL-12332

The CsvRecordConverter is a public interface from camel-csv. You can
implement your own, and configure on the dataformat

On Wed, Mar 7, 2018 at 4:26 PM, Dennis Holunder <de...@gmail.com> wrote:
> But you could make CsvRecordConverter public, so I could implement the
> mapper myself. Or you implement converting of CSVRecord to
> LinkedHashMap, shouldn't be a big deal
>
> 2018-03-07 16:17 GMT+01:00 Claus Ibsen-2 [via Camel]
> <ml...@n5.nabble.com>:
>> Hi
>>
>> Ah okay that is unfortunately in the commons-csv implementation. You
>> would need to report this to them.
>>
>> Sadly there is no way to get the mapping on CSVRecord so we can get
>> the column headers (we could maybe do some reflection as workaround).
>>
>> On Wed, Mar 7, 2018 at 3:29 PM, Dennis Holunder <[hidden email]> wrote:
>>
>>> in camel-csv component
>>> CsvRecordConverters.mapConverter().convertRecord(CSVRecord record)
>>>
>>> it calls CSVRecord.toMap() which returns HashMap but CSVRecord is in
>>> org.apache.commons.csv
>>>
>>> would be great if you could change it.
>>>
>>>
>>>
>>>
>>> 2018-03-07 13:13 GMT+01:00 Claus Ibsen-2 [via Camel]
>>> <[hidden email]>:
>>>> Hi
>>>>
>>>> Can you point to where it creates HashMap, maybe we can change that to
>>>> LinkedHashMap.
>>>>
>>>> On Wed, Mar 7, 2018 at 12:08 PM, Dennis Holunder <[hidden email]> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I need a CSV record mapper which would use maps, but ordered ones,
>>>>> because I need the name of the first header field. Current
>>>>> implementation creates HashMaps, where the original order is lost.
>>>>>
>>>>> I tried to implement my own CsvRecordConverter to produce ordered map,
>>>>> but the interface is not public. This is not expected,
>>>>> CsvDataFormat.setRecordConverter has a public setter accepting this
>>>>> interface.
>>>>>
>>>>> Any workarounds?
>>>>>
>>>>> Den
>>>>
>>>>
>>>>
>>>> --
>>>> Claus Ibsen
>>>> -----------------
>>>> http://davsclaus.com @davsclaus
>>>> Camel in Action 2: https://www.manning.com/ibsen2
>>>>
>>>>
>>>> ________________________________
>>>> If you reply to this email, your message will be added to the discussion
>>>> below:
>>>>
>>>> http://camel.465427.n5.nabble.com/csv-data-format-with-ordered-maps-tp5818212p5818215.html
>>>> To unsubscribe from Camel, click here.
>>>> NAML
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>>
>> ________________________________
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://camel.465427.n5.nabble.com/csv-data-format-with-ordered-maps-tp5818212p5818245.html
>> To unsubscribe from Camel, click here.
>> NAML



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: csv data format with ordered maps

Posted by Dennis Holunder <de...@gmail.com>.
But you could make CsvRecordConverter public, so I could implement the
mapper myself. Or you implement converting of CSVRecord to
LinkedHashMap, shouldn't be a big deal

2018-03-07 16:17 GMT+01:00 Claus Ibsen-2 [via Camel]
<ml...@n5.nabble.com>:
> Hi
>
> Ah okay that is unfortunately in the commons-csv implementation. You
> would need to report this to them.
>
> Sadly there is no way to get the mapping on CSVRecord so we can get
> the column headers (we could maybe do some reflection as workaround).
>
> On Wed, Mar 7, 2018 at 3:29 PM, Dennis Holunder <[hidden email]> wrote:
>
>> in camel-csv component
>> CsvRecordConverters.mapConverter().convertRecord(CSVRecord record)
>>
>> it calls CSVRecord.toMap() which returns HashMap but CSVRecord is in
>> org.apache.commons.csv
>>
>> would be great if you could change it.
>>
>>
>>
>>
>> 2018-03-07 13:13 GMT+01:00 Claus Ibsen-2 [via Camel]
>> <[hidden email]>:
>>> Hi
>>>
>>> Can you point to where it creates HashMap, maybe we can change that to
>>> LinkedHashMap.
>>>
>>> On Wed, Mar 7, 2018 at 12:08 PM, Dennis Holunder <[hidden email]> wrote:
>>>
>>>> Hello,
>>>>
>>>> I need a CSV record mapper which would use maps, but ordered ones,
>>>> because I need the name of the first header field. Current
>>>> implementation creates HashMaps, where the original order is lost.
>>>>
>>>> I tried to implement my own CsvRecordConverter to produce ordered map,
>>>> but the interface is not public. This is not expected,
>>>> CsvDataFormat.setRecordConverter has a public setter accepting this
>>>> interface.
>>>>
>>>> Any workarounds?
>>>>
>>>> Den
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> http://davsclaus.com @davsclaus
>>> Camel in Action 2: https://www.manning.com/ibsen2
>>>
>>>
>>> ________________________________
>>> If you reply to this email, your message will be added to the discussion
>>> below:
>>>
>>> http://camel.465427.n5.nabble.com/csv-data-format-with-ordered-maps-tp5818212p5818215.html
>>> To unsubscribe from Camel, click here.
>>> NAML
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://camel.465427.n5.nabble.com/csv-data-format-with-ordered-maps-tp5818212p5818245.html
> To unsubscribe from Camel, click here.
> NAML

Re: csv data format with ordered maps

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Ah okay that is unfortunately in the commons-csv implementation. You
would need to report this to them.

Sadly there is no way to get the mapping on CSVRecord so we can get
the column headers (we could maybe do some reflection as workaround).

On Wed, Mar 7, 2018 at 3:29 PM, Dennis Holunder <de...@gmail.com> wrote:
> in camel-csv component
> CsvRecordConverters.mapConverter().convertRecord(CSVRecord record)
>
> it calls CSVRecord.toMap() which returns HashMap but CSVRecord is in
> org.apache.commons.csv
>
> would be great if you could change it.
>
>
>
>
> 2018-03-07 13:13 GMT+01:00 Claus Ibsen-2 [via Camel]
> <ml...@n5.nabble.com>:
>> Hi
>>
>> Can you point to where it creates HashMap, maybe we can change that to
>> LinkedHashMap.
>>
>> On Wed, Mar 7, 2018 at 12:08 PM, Dennis Holunder <[hidden email]> wrote:
>>
>>> Hello,
>>>
>>> I need a CSV record mapper which would use maps, but ordered ones,
>>> because I need the name of the first header field. Current
>>> implementation creates HashMaps, where the original order is lost.
>>>
>>> I tried to implement my own CsvRecordConverter to produce ordered map,
>>> but the interface is not public. This is not expected,
>>> CsvDataFormat.setRecordConverter has a public setter accepting this
>>> interface.
>>>
>>> Any workarounds?
>>>
>>> Den
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>>
>> ________________________________
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://camel.465427.n5.nabble.com/csv-data-format-with-ordered-maps-tp5818212p5818215.html
>> To unsubscribe from Camel, click here.
>> NAML



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: csv data format with ordered maps

Posted by Dennis Holunder <de...@gmail.com>.
in camel-csv component
CsvRecordConverters.mapConverter().convertRecord(CSVRecord record)

it calls CSVRecord.toMap() which returns HashMap but CSVRecord is in
org.apache.commons.csv

would be great if you could change it.




2018-03-07 13:13 GMT+01:00 Claus Ibsen-2 [via Camel]
<ml...@n5.nabble.com>:
> Hi
>
> Can you point to where it creates HashMap, maybe we can change that to
> LinkedHashMap.
>
> On Wed, Mar 7, 2018 at 12:08 PM, Dennis Holunder <[hidden email]> wrote:
>
>> Hello,
>>
>> I need a CSV record mapper which would use maps, but ordered ones,
>> because I need the name of the first header field. Current
>> implementation creates HashMaps, where the original order is lost.
>>
>> I tried to implement my own CsvRecordConverter to produce ordered map,
>> but the interface is not public. This is not expected,
>> CsvDataFormat.setRecordConverter has a public setter accepting this
>> interface.
>>
>> Any workarounds?
>>
>> Den
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://camel.465427.n5.nabble.com/csv-data-format-with-ordered-maps-tp5818212p5818215.html
> To unsubscribe from Camel, click here.
> NAML

Re: csv data format with ordered maps

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Can you point to where it creates HashMap, maybe we can change that to
LinkedHashMap.

On Wed, Mar 7, 2018 at 12:08 PM, Dennis Holunder <de...@gmail.com> wrote:
> Hello,
>
> I need a CSV record mapper which would use maps, but ordered ones,
> because I need the name of the first header field. Current
> implementation creates HashMaps, where the original order is lost.
>
> I tried to implement my own CsvRecordConverter to produce ordered map,
> but the interface is not public. This is not expected,
> CsvDataFormat.setRecordConverter has a public setter accepting this
> interface.
>
> Any workarounds?
>
> Den



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2