基本场景:
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);
};
问题:当没有timestamp
字段的 JSON 作为请求发送时,数据库条目根本没有timestamp
字段。
如果使用timestamp: Date
而不是,timestamp: Option[Date]
则 JSON 提取会抛出一个MappingException
.
问:缺少的 JSON 字段/案例类参数如何默认为值?