I have an object with has an subclass as attribute:
case class UpgradeInfo(
@EnumAs upgradeType: UpgradeType.Value,
@EnumAs timeUnit: TimeUnit.Value,
timeQuantity: Int,
start: Date,
end: Date)
case class Upgrade(
@Key("_id") id: ObjectId = new ObjectId,
adId: ObjectId,
upgradeInfo: UpgradeInfo,
price: Double)
Creating and updating the object works fine, but when I try to retrieve the Upgrade object with this code (should retrieve all upgrade objects):
UpgradeDAO.find(MongoDBObject()).toList
I get following exception:
[error] Exception: class models.entities.Upgrade requires value for 'upgradeInfo' (Grater.scala:402)
[error] com.novus.salat.DefaultArg.safeValue$lzycompute(Grater.scala:406)
[error] com.novus.salat.DefaultArg.safeValue(Grater.scala:402)
[error] com.novus.salat.ConcreteGrater.safeDefault(Grater.scala:363)
[error] com.novus.salat.ConcreteGrater$$anonfun$5$$anonfun$apply$3.apply(Grater.scala:262)
[error] com.novus.salat.ConcreteGrater$$anonfun$5$$anonfun$apply$3.apply(Grater.scala:262)
[error] com.novus.salat.ConcreteGrater$$anonfun$5.apply(Grater.scala:262)
[error] com.novus.salat.ConcreteGrater$$anonfun$5.apply(Grater.scala:247)
[error] com.novus.salat.ConcreteGrater.asObject(Grater.scala:247)
[error] com.novus.salat.dao.SalatMongoCursorBase$class.next(SalatMongoCursor.scala:45)
[error] com.novus.salat.dao.SalatMongoCursor.next(SalatMongoCursor.scala:151)
[error] com.novus.salat.dao.SalatMongoCursor.foreach(SalatMongoCursor.scala:151)
[error] com.novus.salat.dao.SalatMongoCursor.to(SalatMongoCursor.scala:151)
[error] com.novus.salat.dao.SalatMongoCursor.toList(SalatMongoCursor.scala:151)
[error] models.entities.UpgradeDAO$.find(Upgrade.scala:47)
[error] models.UpgradeSpecs$$anonfun$1$$anonfun$apply$28$$anonfun$apply$29.apply(UpgradeSpecs.scala:129)
[error] models.UpgradeSpecs$$anonfun$1$$anonfun$apply$28$$anonfun$apply$29.apply(UpgradeSpecs.scala:128)
[error] play.api.test.Helpers$.running(Helpers.scala:40)
[error] models.UpgradeSpecs$$anonfun$1$$anonfun$apply$28.apply(UpgradeSpecs.scala:128)
[error] models.UpgradeSpecs$$anonfun$1$$anonfun$apply$28.apply(UpgradeSpecs.scala:128)
Any idea what I'm doing wrong?
This is caused by a document in your mongo collection which is missing the value for upgradeInfo
.
You have a couple of options here:
upgradeInfo
upgradeInfo
to Option[UpgradeInfo]
and supply a default value of None
upgradeInfo