I know this is going against the very nature of Scala pureconfig ... however ... Is it even feasible to implement with scala pureconfig configuration reading for this case class, so that instead of having strongly typed value( as String) for the constructor parameter "variable" to have Any type or at least String, Integer, Double, Array[Strings], Array[Integer], Array[Double].
case class Filter(
field: String,
operator: String,
variable: String // should support Int , Double , List[String], List[Int]
)
To my poor understanding, neither CoProductHint nor Custom Reader approach will work ...
By default pureconfig doesn't provide a way to read
Any. If for a specific class you would like to readAnythen you can define a codec forAnyin the context of that class:and then you can read
Filterunwrappedconverts aConfigValuetoAnyrecursively.So the answer is yes, it if possible to tell pureconfig how to read
Any.The reason why pureconfig doesn't provide the codec for
Anyby default is becauseAnyis the ancestor of all the classes in Scala and it's impossible to create a codec for anything (e.g. database connections). When you know that you are expecting a restricted set of types, like the ones you listed, you can wrap everything in a coproduct:and then use the default way to extract the coproduct value or a custom codec for
MySupportedTypeUsing a coproduct instead of
Anylimits the possible values thatvariablecan have and let the compiler help you if something is wrong with what you are doing.