scalagenericsimplicit-conversionimplicitpureconfig

pureconfig no manual imports of pureconfig.generic.auto._


The latest updates of pureconfig in the 0.10.* series disabled automatic configuration by default.

import pureconfig.generic.auto._

needs to be manually imported. But I have a class hierarchy, where I do not want to import it every time for a child class.

import pureconfig.ConfigReader
abstract class SparkBaseRunner[T <: Product](implicit A: ConfigReader[T])extends App {}

already expects a configReader. When using this base class:

object MyOperation extends SparkBaseRunner[MyCaseClass] {}

it fails with:

could not find implicit value for parameter A: pureconfig.ConfigReader[foo.bar.my.Type]

unless the above mentioned input is specified manually at each child class. Is there a way to avoid this code duplication? Trying to specify the input in the abstract base class did not work for me as it requires already a ConfigReader object.

edit

Trying to manually get access to the config reader inside the base class also fails:

implicit val configReader = deriveReader[T]
could not find implicit value for parameter A: pureconfig.ConfigReader[T]
could not find Lazy implicit value of type pureconfig.generic.DerivedConfigReader[T]

My Scala version is: 2.11.12


Solution

  • I believe that the config is being read as a single operation already, and there are multiple applications, all doing the below:

    object Ops extends SparkBaseRunner[MyCaseClass]
    

    I can't see a way to avoid duplication since the base class can't infer the configuration since all it has is a generic type T.

    The best solution is to not worry about it and use auto._.

    import pureconfig.generic.auto._