質問

I am configuring my POJO to unmarshal a CSV line, so I declared my attributes as indicated on the camel-bindy official page, and everything went well when unmarshalling.

@DataField(pos = 1) 
private String name; 
... 
getter and setter 

What I need to do is to make the pos attribute configurable, pointing a corresponding property in a properties.file to indicate the position of the name column in the CSV line.

Is it possible to implement such behaviour ?

役に立ちましたか?

解決

No this is not possible. And there is no plans to support this in the future.

You can take a look at some of the other CSV components such as beanio which allows to define binding information in external configuration files.

他のヒント

I would be interested to know if it's possible to do with Bindy, but nothing seems to indicate it in the documentation.

What you could do when you are unsure of the position of your properties position is using the camel CSV data unmarshaling.

http://camel.apache.org/csv.html

you create a route that check for csv files in a given folder, unmarshal each csv lines to List<String> and send that List<List <String>> to a bean of yours that will do the processing. Given that the first line of your csv file is the columns, in your bean you'll know the position of each attributes and you'll be able to map the csv strings of data to the attributes of your bean.

route that process file and unmarshall lines :

<route>
    <from uri="file:///path/where/are/my/csvfiles?delete=true />
    <unmarshal><csv /></unmarshal>
    <to uri="bean:myCsvMapper?method=doHandleCsvData" />

Your bean:

public void doHandleCsvData(List<List<String>> csvData){
   // with first line (column names) get the position of your attributes

   // for next lines do the mapping between the position and the attributes 
   // of your data bean
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top