My case class contains a property of type Any, how do I create an implicit for Any?

166 Views Asked by At

I have a case class like:

case class House(id: Int, name: String, meta: Any)

I get this compile error:

implicit not found for 'House.value': reactivemongo.api.bson.BSONReader[Any]

I tried creating a custom BSONReader like:

 implicit object anyBSONReader extends BSONReader[Any] {
    override def readTry(bson: BSONValue): Try[Any] = bson.asTry[Any].map(v => v.asInstanceOf[Any]).toOption
  }

I then imported this anyBSONReader that like this:

case class House(id: Int, name: String, meta: Any)
object House {
    implicit object anyBSONReader extends BSONReader[Any] {
        override def readTry(bson: BSONValue): Try[Any] = bson.asTry[Any].map(v =>  
            v.asInstanceOf[Any])
 }
   implicit val houseHander = Macros.hander[House]
}

I still get the same error message

0

There are 0 best solutions below