uniVocity / univocity-parsers

uniVocity-parsers is a suite of extremely fast and reliable parsers for Java. It provides a consistent interface for handling different file formats, and a solid framework for the development of new parsers.
904 stars 249 forks source link

Dynamic mapping of column names to attributes #348

Open khuzayfa opened 5 years ago

khuzayfa commented 5 years ago

Hi, I have seen the closed issue #287 . I have similar case, but in my situation column name for one attribute of POJO frequently changes. Let's say I am receiving every week or month some file where I have a column <Passed Orders (July 2019)>. My application parses this csv file with BeanListProcessor to the desired POJO instances. However, next time I will receive a file where that same column would change to <Passed Orders (August 2019)> and this keeps happening every fixed period. Every time when I have such situation it is not that efficient (and some times feasible) to modify the code (either using the solution from #287 or using @Parsed annotations). So, I wanted to ask, is it possible to add some regex style expression to the parsing annotation or to the solution from #287, so that I will just look for the column %Passed Orders%. I may have other aliases/names to the same column for new costumers, so solution similar to @Parsed annotation with (fields = {}) would be the best, but I am open to other ideas as well.

jbax commented 5 years ago

Is the column always in the same position? If it is you can map its index. Another option is to read the first line to manually determine the headers, then map the headers to their positions. It's a bit more work but you can do it without a regex right now.

I'll look into using regex for matching headers in version 3.0.0.

Thank you for using our parsers!

khuzayfa commented 5 years ago

Thank you for your answer. Column names for different clients have different positions. So matching by position is not an option for me. Regarding the parsing first line of file or header, I thought about that and was considering it as an option if I cannot find better way of solving the question and thus first wanted to ask from authors.