Hi, I was halfway through reporting this issue when I found the (easy) solution but I figured I will report it anyway since it might be useful for someone else experiencing the same issue.
Problem
I have an ADT defined in a dependency of our project and I've been using chimney
to transform it into our own ADT so we don't get to share the same domain code from this dependency. Here's a simple example that reproduces my issue:
sealed trait Animal
object Animal {
sealed trait Reptile extends Animal
sealed trait Mammal extends Animal
case object Cat extends Mammal
case object Dog extends Mammal
case object Lizard extends Reptile
case object Turtle extends Reptile
}
Basically I define the same ADT in our project with a small difference to help the type inference system:
sealed trait Animal extends Product with Serializable
And I have another class that makes use of it in this way:
case class Foo(animals: Map[Animal, Map[Animal.Reptile, BigDecimal]])
The transformation works seamlessly by defining a custom Transformer[LibAnimal, Animal]
.
Now I have the need to use enumeratum
for my local representation of Animal
in order to construct valid values from a string representation withNameInsensitive
. And so my new ADT is defined as follows:
import enumeratum._
sealed trait Animal extends EnumEntry
object Animal extends Enum[Animal] {
val values = findValues
sealed trait Reptile extends Animal
sealed trait Mammal extends Animal
case object Cat extends Mammal
case object Dog extends Mammal
case object Lizard extends Reptile
case object Turtle extends Reptile
}
But now chimney
fails to compile giving me the following error:
[info] Compiling 5 Scala sources to /workspace/xxx/target/scala-2.12/classes ...
[error] /workspace/xxx/Converter.scala:27:33: type mismatch;
[error] found : scala.collection.immutable.Map[remote.Animal,scala.collection.immutable.Map[local.Animal.Reptile with Product with Serializable,scala.math.BigDecimal]]
[error] required: Map[remote.Animal,Map[local.Animal.Reptile,BigDecimal]]
[error] remoteFoo.into[Foo].transform
[error] ^
[error] one error found
[error] (service / Compile / compileIncremental) Compilation failed
[error] Total time: 5 s, completed Sep 19, 2018 7:15:31 PM
Solution
Define the ADT by mixing Product with Serializable
like this:
sealed trait Animal extends EnumEntry with Product with Serializable