简体   繁体   中英

Using PureConfig with Refined?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM