0
に結合
私のコントローラは、RESTサービスのためのものであり、JSON受信しなければならない:私はこれに応じてクラスを作成[PlayFramework 2.5] [ジャワ] JSON POST要求フォーム
body {
"text": "string",
"page": 0
}
:
@ApiModel(
value="FSearch",
description = "Parameters for user search"
)
public class FSearch {
@ApiModelProperty(
value = "Text , to lookup for",
notes = "Can be empty",
required = false
)
public String text;
@ApiModelProperty(
value = "Page number of search results",
required = true
)
@Constraints.Required
public int page;
}
マイコントローラbidningは次のようになります。
@BodyParser.Of(BodyParser.Json.class)
public Result search(){
Form<FSearch> searching = formFactory.form(FSearch.class).bindFromRequest();
if (searching .hasErrors()) {
return badRequest(searching .errorsAsJson());
}
//Another not releated code
return ok(Json.toJson(result));
}
今、私はこのようなデータを送信してテストするとき:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ "text": "bla", \ "lol": 0 \ }'
は、だから私は、このJSON送ります:代わりに、ページの笑
body {
"text": "bla",
"lol": 0
}
お知らせしますが、フォームがまだエラーなしバインドされ...私は、変数名がで一致していることを確認するために何をすべき jsonバインディング?