1

Reactive mongoドライバーでplay-frameworkを使用しています。次の例のようなパスのparamとしての私のidは、ルートのルーティングでPlay-Framework:パラメーターcompanyIdをBSONObjectIDとして解析できません:間違ったObjectId

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)) 
} 

私は簡単だ:

GET  /company/:companyId/users-detail  controllers.CompanyController.userDetail(companyId: BSONObjectID) 

マイBSONObjectIdが簡単にマッピングされ、当社のroutesファイルに反応モンゴBSONObjectIdを扱うために、私は次のバインダーを作成しています私のリクエストハンドラパスのパラメータで。しかし、以下のように、私は上記のルートの後に次のルートを使用していたときに:私はBadRequest次取得しています

GET /company/detail  controllers.CompanyController.companyDetail 

For request 'GET /company/detail?t=1466673779753' [Cannot parse parameter companyId as BSONObjectID: wrong ObjectId: 'teams'] 

しかし、私は以下のようにルートを切り替える:

GET /company/detail  controllers.CompanyController.companyDetail 
GET  /company/:companyId/users-detail  controllers.CompanyController.userDetail(companyId: BSONObjectID) 

サービス正常に実行されます。私はまだ実際の問題が何であるかは分かりません。これは、プレイフレームワークの問題、または何か私のコードに間違っていますか?

答えて

2

あなたは再実装QueryBindable、BSON 1がすでにプレイプラグインによって提供されるのに対し、まず:see sample

次にあなたがBSONObjectIDの有効な表現ではない値"teams"を渡します。

関連する問題