Pure config can't pars capital letters in conf
sealed trait Occupation extends Product with Serializable
object Occupation {
case class Employed(job: String) extends Occupation
object Employed {
implicit val employedReader = deriveReader[Employed]
}
case object Unemployed extends Occupation {
implicit val unemployedReader = deriveReader[Unemployed.type]
}
case object Student extends Occupation {
implicit val studentReader = deriveReader[Student.type]
}
implicit val occupationReader = deriveReader[Occupation]
}
case class WorkingPerson(name: String, surname: String, occupation: Occupation)
val res = ConfigSource.string("{ name: Isaac, surname: Newton, occupation.type: student }").load[WorkingPerson]
It works, but I need enum value like 'StudenT' and if I do so I got "ConvertFailure(UnexpectedValueForFieldCoproductHint(Unquoted("student"))"
If you want to change how the field is being read you need to provide a
hint
.In this case, adding
FieldCoproductHint[Occupation]
is what you need to doI created a working example in scastie
Do you really need to use the Semi-Automatic derivation? You can get the same result just using the automatic one.
Here is the working example in scatsie
build.sbt
main.scala