Custom Types using pureconfig?

404 views Asked by At

I am using PureConfig with Refined. I have the following case class:

case class Config(port: ServerPort, interface: String)

ServerPort is a custom type that I have defined using Refined. I am using pureconfig to load a conf file into the Config case class like so:

import com.api.models.Config
import com.typesafe.config.ConfigFactory
import eu.timepit.refined.W
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric.Greater
import pureconfig.{ConfigReader, loadConfig}

object Configuration {

  type ServerPort = Int Refined Greater[W.`1024`.T]

  val port = 8080
  val interface = " 127.0.0.1"


  val config = ConfigFactory.load()

  val connection: Config = loadConfig[Config](config,"connection").getOrElse(Config(8080,"127.0.0.1"))

}

However whenever I run this I get the below error:

Error:(21, 37) could not find a ConfigReader instance for type Config
  implicit val reader = ConfigReader[Config].map(item => new Config(item.port,item.interface))

Is there a way I can use pureconfig to read custom types?

0

There are 0 answers