MappingIterator<Map<?, ?>> mappingIterator = csvMapper.reader(Map.class).with(bootstrap).readValue(file.getInputStream());
Above code throws this error:
java.util.LinkedHashMap cannot be cast to com.fasterxml.jackson.databind.MappingIterator
MappingIterator<Map<?, ?>> mappingIterator = csvMapper.reader(Map.class).with(bootstrap).readValue(file.getInputStream());
Above code throws this error:
java.util.LinkedHashMap cannot be cast to com.fasterxml.jackson.databind.MappingIterator
That happens because the method to get MappingIterator is readValues instead of readValue.
The second method "readValue" (without 's') is used to read a single value from the schema.
I was having the same problem with an example I got from directly convert CSV file to JSON file using the Jackson library
Which version of the jackson databind and dataformat libraries are you using? There is a method readValues(InputStream)
that returns a MappingIterator
. But it seems there were a few changes in that area between the versions.
The code csvMapper.reader(Map.class).with(bootstrap).readValue(file.getInputStream());
returns LinkedHashMap
. But MappingIterator
cannot hold LinkedHashMap
.
Not sure though, but try explicitly casting as shown below:
(MappingIterator)(csvMapper.reader(Map.class).with(bootstrap).readValue(file.getInputStream()));