Hi,
I have a piece of code in which looks like this
class UserServlet extends ScalatraServlet with LiftJsonRequestBody {
I expect Json request coming from the client from which the user object is extracted like this
post("/save") {
parsedBody match {
case JNothing =>
halt(400, "Invalid Json")
case json: JObject => {
val user = json.extract[User]
UserDAO.save(user)
}
case _ =>
halt(400, "Unknown Json")
}
}
The user object is
case class User(
@Key("_id") id: ObjectId = new ObjectId,
firstName: String,
lastName: String,
...
...
)
I have a problem when i use ObjectId since there is no serializer for that. In other situations I could have added a serializer like this
implicit val formats = new net.liftweb.json.DefaultFormats {
override def dateFormatter = new SimpleDateFormat("dd/MM/yyyy")
} + new EnumerationSerializer(EnumList) + new ObjectIdSerializer
when i do something similar here I get ambiguous references to Formats since jsonFormats is also present in LiftJsonRequestBody. Is there a way to add custom serializers to jsonFormats in LiftJsonRequestBody? Any other way?
Regards | Vikas