4

I have the below conf file:

connection.port = 8080
connection.interface = "127.0.0.1"

I am trying to use refined and refined-pureconfig when reading this file. I have the below class:

import com.api.models.{Config, Connection}
import com.typesafe.config.ConfigFactory
import pureconfig.error.ConfigReaderFailures
import pureconfig.loadConfig

object Configuration {
  val config = ConfigFactory.load()

  val stuff: Either[ConfigReaderFailures, Connection] = loadConfig[Connection](config)



 stuff match {
   case Left(left) => println(left)
   case Right(right) => println(right)
 }
}

This is reading the below case class:

case class Connection(port: Int, interface: String)

However when I try to compile this, I get the following error:

Error:(19, 79) could not find implicit value for parameter reader: pureconfig.Derivation[pureconfig.ConfigReader[com.api.models.Connection]]
  val stuff: Either[ConfigReaderFailures, Connection] = loadConfig[Connection](config)

I'm really not sure how to create such an implicit?

Nespony
  • 1,253
  • 4
  • 24
  • 42

1 Answers1

1

Most likely you're missing an import probably this one: import pureconfig.generic.auto._

see https://pureconfig.github.io/docs/

If you're interested in what's happening here you can look into "typeclass derivation"

EDIT: Note that right now this has nothing to do with refined types as your code snipped is not using them.

Dominic Egger
  • 1,016
  • 5
  • 7
  • I ran into a similar issue and adding this import statement worked for me. However, the IDE shows that this import is unused. Do you know why the import is so crucial? – adarsh hegde Feb 06 '19 at 21:52
  • 1
    so by "the IDE" I assume you mean intellij? it is quite notorious to have issues with implicit values. basically intellij has it's own scala-compiler to check your coder and sometimes it's just straight up wrong (you can even have cases where intellij will underline code in red that works perfectly fine). the import itself is important because that's where the implicits are defined that pureconfig uses to create Decoders for a given type at compile time. – Dominic Egger Feb 07 '19 at 10:00