Macros.handler for my case class gives "No unapply function found" error.

165 views
Skip to first unread message

Rich Bolen

unread,
Sep 22, 2015, 11:29:20 AM9/22/15
to ReactiveMongo - http://reactivemongo.org
I'm using reactivemongo 0.11.7 and scala 2.11.7.

I have the following case class:

case class Reading(
@BeanProperty var Site_ID: String,
@BeanProperty var Last_Reading_Time: Date,
@BeanProperty var Command_Ind: Byte,
@BeanProperty var Run_Ind: Option[Byte] = None,
@BeanProperty var Relay_Ind: Option[Byte] = None,
@BeanProperty var XferSwitch_Ind: Option[Byte] = None,
@BeanProperty var Outage_Ind: Option[Byte] = None,
@BeanProperty var kW_u: Option[Double] = None,
@BeanProperty var kWh_u: Option[Double] = None,
@BeanProperty var kW_g: Option[Double] = None,
@BeanProperty var kWh_g: Option[Double] = None,
@BeanProperty var Freq_u: Option[Double] = None,
@BeanProperty var Freq_g: Option[Double] = None,
@BeanProperty var PF_u: Option[Double] = None,
@BeanProperty var PF_g: Option[Double] = None,
@BeanProperty var Panel_temp: Option[Double] = None,
@BeanProperty var Fuel_Level: Option[Double] = None,
@BeanProperty var Van_u: Option[Double] = None,
@BeanProperty var Vbn_u: Option[Double] = None,
@BeanProperty var Vcn_u: Option[Double] = None,
@BeanProperty var Vab_u: Option[Double] = None,
@BeanProperty var Vbc_u: Option[Double] = None,
@BeanProperty var Vac_u: Option[Double] = None,
@BeanProperty var Van_g: Option[Double] = None,
@BeanProperty var Vbn_g: Option[Double] = None,
@BeanProperty var Vcn_g: Option[Double] = None,
@BeanProperty var Vab_g: Option[Double] = None,
@BeanProperty var Vbc_g: Option[Double] = None,
@BeanProperty var Vac_g: Option[Double] = None,
@BeanProperty var Ia_u: Option[Double] = None,
@BeanProperty var Ib_u: Option[Double] = None,
@BeanProperty var Ic_u: Option[Double] = None,
@BeanProperty var Ia_g: Option[Double] = None,
@BeanProperty var Ib_g: Option[Double] = None,
@BeanProperty var Ic_g: Option[Double] = None,
@BeanProperty var kVA_u: Option[Double] = None,
@BeanProperty var kVAR_u: Option[Double] = None,
@BeanProperty var kVARh_u: Option[Double] = None,
@BeanProperty var kVA_g: Option[Double] = None,
@BeanProperty var kVAR_g: Option[Double] = None,
@BeanProperty var kVARh_g: Option[Double] = None)

When I call Macros.handler[Reading] i get the following error:

[error] /Users/rbolen/git/nop-commons-parent-scala/json/src/main/scala/com/pa/json/ReactiveMongoHandlers.scala:467: No unapply function found for com.pa.models.pogens.Reading
[error]   implicit val readingFormat = Macros.handlerOpts[Reading, Options.Verbose]

This seems to be a fairly vanilla case class.  Is there something here that is confusing the macros code?  I've implemented a Byte reader/writer pair to see if that was an issue.  I think there is already a standard handler for Double. 

Here's that code:
implicit def byteReader = new BSONDocumentReader[Byte] {
def read(doc: BSONDocument): Byte = {
doc.getAs[BSONInteger]("byteValue").get.as[Int].toByte
}
}

implicit def byteWriter = new BSONDocumentWriter[Byte] {
def write(b: Byte): BSONDocument = {
BSONDocument("byteValue" -> new BSONInteger(b.toInt))
}
}

Any ideas?

Thanks,
Rich

Rich Bolen

unread,
Sep 22, 2015, 4:52:10 PM9/22/15
to ReactiveMongo - http://reactivemongo.org
So I'm a relative scala newby as well.  It's due to the 22 field limit for case classes.  I could try a non-case class.  I've read it might work but the behavior of Macros.handler is undefined with non-case classes.

Cédric Chantepie

unread,
Sep 23, 2015, 6:47:58 AM9/23/15
to ReactiveMongo - http://reactivemongo.org
Hi, You're right, the doc can be improved about this point (usually omitted as this is a limitation common to most of macros lib). Best regards
Reply all
Reply to author
Forward
0 new messages