convertValue from AbstractMappingStrategy disappear at 5.0
Brought to you by:
aruckerjones,
sconway
hello !
i'm currently trying to modify the dependancy of opencsv from. 4.6 to at least 5.0.
An old developer of my project was overriding "convertValue" of AbstractMappingStrategy.
Unfortunatelly this method disappear in 5.0 , how I can do to use a custom "convertValue" ??
Thanks for your answer ;)
That depends very much on what you're trying to do.
convertValue() was part of the Introspection code that we removed in favor of Reflection in 5.0. There is no direct analog in 5.0, I think.
We are implementing two classes using ColumnPositionMappingStrategy and HeaderColumnNameTranslateMappingStrategy .
For both we overrided convertValues because we have some custom converters to apply for some specific columns .
For exemple we have an "Image" column in our csv , we have multiple urls separated by | , and the goal of override this method was to extract and split these value and return a value Object (but in fact a List)
Why not use CsvBindAndSplitByName or CsvBindAndSplitByPosition?
Closed for lack of activity.
I reopen this ticket as i'm block to update 4.4 to 5.5 because convertValue is not available , there is definitely now way to override something like this ? :(
I cannot use CsvBindAndSplitByName because we do some other transformations (not only split the result but some other transformations mapping etc...)
We would have to know exactly what you're doing. I'm fairly well convinced that we've provided for every possible conversion need.
I think a code page is better than explanation :
First we are using the parsing of open csv with two strategy (parse by column position or column names)
We created a class who extends HeaderColumnNameTranslateMappingStrategy. after the value is parsed we need to apply automatically some converter that's we needed to replace
by
}
our method do this thing
I have the same problem (missing
convertValuemethod).My problem is that I have a bean (POJO) and multiple CSV providers. Each provider comes with different format for a ZonedDateTime field from bean (it's only an example).
My impression is that version 5 comes to improve the part with annotation but unfortunately not everything comes down to annotations. I need a method to achieve the same result programatically, without to use annotations (
converterin my particular example).Last edit: Decebal Suiu 2021-12-07
I hear you that annotations aren't the solution to everything, and I agree. Ideally, we would have the option to specifcy bean bindings through an XML configuration file. I'm not sure I still have the energy to implement that, though.
I can say this: if you are able to use annotations, your problem is easily solved starting in version 5.4. Use the "profiles" attribute to CsvDate, then pass the profile you want to CsvToBeanBuilder when you parse.
In the end I solved the problem with an override of
determineConverter:I don't know if it's the right solution but I am satisfied by this solution.
User implemented workaround.