I am using play-framework with Reactive mongo drivers. For handling reactive mongo BSONObjectId
in our routes file, i am creating following binders:
object StringToBSONObjectIdBinder {
/* This is for Path Parameter*/
implicit object pathBindableBSONObjectID extends play.api.mvc.PathBindable.Parsing[BSONObjectID](
BSONObjectID(_), _.stringify,
(key: String, e: Exception) =>
"Cannot parse parameter %s as BSONObjectID: %s".format(key, e.getMessage))
/* This is for query String*/
implicit object queryStringBindableBSONObjectID extends play.api.mvc.QueryStringBindable.Parsing[BSONObjectID](
BSONObjectID(_), _.stringify,
(key: String, e: Exception) =>
"Cannot parse parameter %s as BSONObjectID: %s".format(key, e.getMessage))
}
In routing i am easily route my id as a path param like following example:
GET /company/:companyId/users-detail controllers.CompanyController.userDetail(companyId: BSONObjectID)
My BSONObjectId
easily mapped with my request handler path param. But when i am using following route after above route as below:
GET /company/detail controllers.CompanyController.companyDetail
I am getting following BadRequest
:
For request 'GET /company/detail?t=1466673779753' [Cannot parse parameter companyId as BSONObjectID: wrong ObjectId: 'teams']
But when i switch the routes as below:
GET /company/detail controllers.CompanyController.companyDetail
GET /company/:companyId/users-detail controllers.CompanyController.userDetail(companyId: BSONObjectID)
Services run successfully. I am still no getting what actual problem is. This is play-framework issue, or something wrong with my code?