Play フレームワーク 2.1.1 (Java) に問題があり、無効な JSON を送信していると通知されます。Play フレームワーク 2.x と 2.1.0 で同様の/おそらく同じ問題が発生しましたが、Play Framework 2.1.1 で解決されているはずでした: Play Framework 2.1 で無効な JSON を参照してください。
これは私がコードで行っていることです。少し短くしようとしました:
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParser;
import play.libs.Json;
import play.mvc.BodyParser;
@BodyParser.Of(BodyParser.Json.class)
public static Result login() {
JsonNode json = request().body().asJson();
}
私が実行すると:
curl -v -H "Content-Type: application/json" -X POST -d '{"email":"test@test.de","password":"test"}' http://localhost:9000/mobile/login
次の応答が返されます。
< HTTP/1.1 400 Bad Request
< Content-Type: text/html; charset=utf-8
< Content-Length: 1917
...
<p id="detail">
For request 'POST /mobile/login' [Invalid Json]
</p>
...
プロジェクトをクリーンアップして、数回再実行しました。play aboutを実行すると、次の出力が得られます。
[info] Loading project definition from /path/to/project
[info] Set current project to FFPushAlarmPlay (in build file:/path/to)
[info] This is sbt 0.12.2
[info] The current project is {file:/path/to}...
[info] The current project is built against Scala 2.10.0
[info] Available Plugins: play.Project, sbt.PlayProject, com.typesafe.sbteclipse.plugin.EclipsePlugin, com.typesafe.sbtidea.SbtIdeaPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.9.2
私はひどく間違ったことをしていますか?これは私の最初の Play 2 プロジェクトであるため、どんな助けも大歓迎です!
更新: AFNetworking を使用して JSON を自動的に構築する iOS クライアントもあり、そこでも無効な JSON 応答が返されることを忘れていました。したがって、これを引き起こしているのは無効なJSONではないようです...