score:-1

Can be this a solution?

def isCaseClassEmpty(product: Product): Boolean =
    product.productIterator.forall {
      case None => true
      case Some(x: Product) => isCaseClassEmpty(x)
      case _ => false
    }

case class Inner(b: Option[Int])
case class Root(a: Option[String]: inner: Option[Inner])

val root = Root(None, None))
isCaseClassEmpty(root) // true

val root = Root(None, Some(Inner(None)))
isCaseClassEmpty(root) // true

val root = Root(None, Some(Inner(Some(5))))
isCaseClassEmpty(root) // false

val root = Root(Some("test"), None)
isCaseClassEmpty(root) // false

Cheers :-)

score:1

You can add a requirement on the case class so serialization will fail:

case class Person(  name: String, 
                    ssn: String,
                    homePhone: Option[Long],
                    cellPhone: Option[Long]){

  require(homePhone.isDefined || cellPhone.isDefined, "Person requires at least one phone number")
  require(ssn.length() == 9 && ssn.forall(Character.isDigit(_)), "ssn must be a String of 9 digits")
}

Related Query

More Query from same tag