Caching and reusing HeaderColumnNameMappingStrategy instances
Brought to you by:
aruckerjones,
sconway
Hi,
I have a question regarding type HeaderColumnNameMappingStrategy<T>
. I tried looking in documenation but sorry couldn't find what I am looking for, couldn't find any user mailing list email either. Apologies if raising a ticket here is not the right way to seek help.
My question - Is it ok to cache and reuse instance of HeaderColumnNameMappingStrategy<T>
? Motivation is to avoid redoing any possible bean introspection using reflection on every CSV file parsing.
Thank you,
Kapil
Eh, not exactly. If you want, you can instantiate a mapping strategy yourself, pass it in to CsvToBeanBuilder.withMappingStrategy(), and keep a reference to it. Theoretically, you could use it again, though I don't think it's made for doing that. We haven't tested reuse for reading. (Writing works fine because writing is rather a different beast anyway.) If nothing else, I'm sure the line numbers will be all off in any error messages you get. It wouldn't surprise me if other things break as well.
Unless you're processing thousands of CSV files, I doubt the setup is taking up significant time. Do you have a specific need, or are you simply hoping to optimize something you think you can optimized?
And opening a ticket here for help is the right way to seek help. You and your questions are welcome here.
Many thanks for your prompt reply.
I haven't encountered any performance issue yet. I am at very initial stage, was making myself familiar with the opencsv api. I have done some initial functional tests for output correctness. I haven't measured what performance improvement it would make (if any) by caching instances of
HeaderColumnNameMappingStrategy<T>
. Was just wondering what obvious improvements I can make.Good I asked this question here. My use case is to do just csv reading at this point. As suggested, I won't cache mapping strategy instances. Easiest I suppose is just to set the target bean type on
CsvToBeanBuilder
instance (withType
method).Thank you.