Support java.util.UUID
Brought to you by:
aruckerjones,
sconway
Support for UUID type without custom converter that uses java.util.UUID.fromString and toString to read/write values.
Current result: com.opencsv.exceptions.CsvDataTypeMismatchException: Conversion of 7F804F85-0064-4E96-8260-3FD47EA6A8BB to java.util.UUID failed
Expected result: successful parsing of valid UUID
If you have written a custom editor could you please send the code for your custom converter because quite honestly if we create our own UUID annotation it would probably work the same way.
That and I wrote the following test using your value just to see if the string may be an incorrect format and it passed. I had to do an equalsIgnoreCase because the toString method makes it lowercase.
What I am wondering is if the string you are passing in has whitespace at the beginning or end which causes an NumberFormatException to be thrown which then would be converted to the exception you are seeing. Try adding a trim() to the string before you pass it into the fromString().
That said if you did not then just let me know because I will look at adding an converter for UUID.
Last edit: Scott Conway 2020-12-23
… I think you might be missing something, Scott. This conversion is not supported, and the exception thrown is expected. The converter would be just as easy to write as Elliot suggests: it would probably be ConverterUUID alongside ConverterPrimitive and the rest. ConverterEnum would be the closest to the required level of complexity. It would not require a new annotation.
Yeah I sort of thought that as I was ending up the email.
I had already decided to create a converter along the lines of your suggestion. Will definitely look at ConverterEnum, I was looking at ConverterCurrency.
My custom converter works fine, UUID seems common enough that Open CSV can support it without the need for an annotation. Taking a quick look at the source code (AbstractMappingStrategy.determineConverter) it looks like Currency and Enums are supported without annotations. Perhaps we can add similar functionality for UUID?
Here is my custom converter
Great! Thank you
On Sun, Dec 27, 2020 at 5:50 PM Scott Conway sconway@users.sourceforge.net
wrote:
Related
Feature Requests:
#143Code has been merged in and will go out with the 5.4 release.