kantan.csv icon indicating copy to clipboard operation
kantan.csv copied to clipboard

could not find implicit value for evidence parameter of type kantan.csv.HeaderDecoder

Open ivandmay opened this issue 4 years ago • 8 comments

Hi!

Trying to use your library and it does not seem to want to work. I took your example code and pasted it into a worksheet with all required imports. Had to wrap everything into an object.

I also followed https://nrinaudo.github.io/kantan.csv/rows_as_case_classes.html and was impressed by the simplicity, but unfortunately that did not work either

After following that, it complains about a misisng implicit HeaderDecoder and a missing ReadEngine. I assumed this would be taken care off by the generics import, but it shows as unused and comes up as a warning when compiling

Any ideas?

import kantan.csv._         // All kantan.csv types.
import kantan.csv.ops._     // Enriches types with useful methods.
import kantan.csv.generic._ // Automatic derivation of codecs.

object Poespas {
// Reading from a file: returns an iterator-like structure on (Int, Int)
new File("points.csv").asCsvReader[(Int, Int)](rfc)

// "Complex" types derivation: the second column is either an int, or a string that might be empty.
new File("dodgy.csv").asCsvReader[(Int, Either[Int, Option[String]])](rfc)

case class Point2D(x: Int, y: Int)

// Parsing the content of a remote URL as a List[Point2D].
new java.net.URL("http://someserver.com/points.csv").readCsv[List, Point2D](rfc.withHeader)

// Writing to a CSV file.
new File("output.csv").asCsvWriter[Point2D](rfc)
.write(Point2D(0, 1))
.write(Point2D(2, 3))
.close()

// Writing a collection to a CSV file
new File("output.csv").writeCsv[Point2D](List(Point2D(0, 1), Point2D(2, 3)), rfc)}

ivandmay avatar Aug 07 '20 15:08 ivandmay

I think you're possibly not compiling the code you pasted: this code does not compile, but not because of lacking implicits: because it lacks import java.io.File.

When I add it, everything works fine (I tried it against kantan.csv 0.6.0 because I had a project ready for that, but I'm pretty sure it works for other versions as well).

Can you confirm that when you fix the lacking import, everything compiles? If not, can you give me more information? The code itself is not enough, because it compiles fine locally. Maybe your buildfile as well, or even a tarball of your project?

nrinaudo avatar Aug 07 '20 15:08 nrinaudo

Thanks for responding... Sorry cut off the File io import when I pasted, so that is not the problem.

Unfortunately I cannot send you my project files, as they are private. What information do you need?

ivandmay avatar Aug 07 '20 15:08 ivandmay

Ok so created a new project for the basic scala seed and copied everything in there.

asdfmksdfakl.zip

ivandmay avatar Aug 07 '20 15:08 ivandmay

This is perfect, but unfortunately, it confirms my suspicions: there's nothing wrong with either the project or code:

sbt compile                                                                                                                                                                                                                                  
[info] Loading global plugins from /home/nicolas/.sbt/1.0/plugins/project
[info] Loading settings for project global-plugins from idea.sbt,plugins.sbt ...
[info] Loading global plugins from /home/nicolas/.sbt/1.0/plugins
[info] Loading project definition from /home/nicolas/Downloads/asdfmksdfakl/project
[success] Generated .bloop/asdfmksdfakl-build.json
[success] Total time: 1 s, completed Aug 7, 2020 5:36:03 PM
[info] Loading settings for project root from build.sbt ...
[info] Set current project to asdfmksdfakl (in build file:/home/nicolas/Downloads/asdfmksdfakl/)
[info] Executing in batch mode. For better performance use sbt's shell
[success] Total time: 0 s, completed Aug 7, 2020 5:36:04 PM

Can you run the same thing and paste the output, maybe?

nrinaudo avatar Aug 07 '20 15:08 nrinaudo

All right I found the issue. It seems to be unhappy with the org joda time package. How do you add a decoder for that?

ivandmay avatar Aug 07 '20 15:08 ivandmay

Well, you have a few options:

  • use an older version of kantan.csv, we used to support joda.
  • write one yourself - for example by looking at how older versions of kantan.csv did it
  • drop joda and use java.time - you're clearly running Java 8 (kantan.csv is not supported for lower versions), so there really is no reason to use joda.

nrinaudo avatar Aug 07 '20 15:08 nrinaudo

Thanks for your help

ivandmay avatar Aug 07 '20 15:08 ivandmay

Btw not sure if this is the right place to request this. If you have a missing implicit converter on a library like anorm for example, you actually get an error message that states what type is missing a converter. Think that might be a nice touch here.

ivandmay avatar Aug 07 '20 20:08 ivandmay