Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Unable to modify nested case class #418

Description

@masonedmison

Given the following simple example:

package diffxsandbox
import com.softwaremill.diffx.generic.auto._
import com.softwaremill.diffx.Diff

case class Address(house: Int, street: String)
case class Person(name: String, address: Address) {
  def diff(other: Person) = {
    val add = Diff.summon[Address]

    val d = 
      Diff.summon[Person]
        .modify(_.address)
        .setTo(add)

    d.apply(this, other)
  }
}

object diffxdemo extends App {
  val a1 = Address(123, "Robin St.")
  val a2 = Address(456, "Robin St.")
  val p1 = Person("Mason", a1)
  val p2 = Person("Mason", a2)

  println {
    p1.diff(p2).isIdentical
  }
}

we are receiving the following stack trace

error] java.lang.ClassCastException: class java.lang.Integer cannot be cast to class scala.Product (java.lang.Integer is in module java.base of loader 'bootstrap'; scala.Product is in unnamed module of loader sbt.internal.ScalaLibraryClassLoader @616527ba)
[error]         at magnolia1.ReadOnlyParam$$anon$3.dereference(interface.scala:213)
[error]         at com.softwaremill.diffx.generic.DiffMagnoliaDerivation.$anonfun$join$3(DiffMagnoliaDerivation.scala:19)
[error]         at scala.collection.immutable.ArraySeq.map(ArraySeq.scala:75)
[error]         at scala.collection.immutable.ArraySeq.map(ArraySeq.scala:35)
[error]         at com.softwaremill.diffx.generic.DiffMagnoliaDerivation.$anonfun$join$2(DiffMagnoliaDerivation.scala:14)
[error]         at com.softwaremill.diffx.DiffxSupport.nullGuard(DiffxSupport.scala:20)
[error]         at com.softwaremill.diffx.DiffxSupport.nullGuard$(DiffxSupport.scala:14)
<elided...>

Does diffx support modification of nested case class parameters? If I instead provide Diff.useEquals[Address] instead of the automically derived instance, the example runs successfully.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions