Basic scenario:
case class Something(
date: Option[Date],
timestamp: Option[Date] = Some(new Date)
);
class Users private() extends MongoRecord[Users] with ObjectIdPk[Users] {
def meta = Users;
object things extends MongoCaseClassListField[Users, Something](this);
};
object Users extends Users with MongoMetaRecord[Users] {
};
def something(json: JValue) = {
val something = json.extract[Something];// does not have a timestamp field.
decompose(something); // again no timestamp field.
Users.where(_.email eqs email).findAndModify(_.things addToSet something).updateOne(true);
};
Problem: When a JSON without a timestamp
field is sent as a request, the database entry does not have a timestamp
field at all.
If timestamp: Date
instead of timestamp: Option[Date]
is used, the JSON extraction throws a MappingException
.
Q: How can a missing JSON field/case class param default to a value?