是否可以让 Play Framework 1 处理 post 请求中发送的 JSON?连接到后端的开发人员不想发送带有 & 符号作为分隔符的键/值对,他想发送 JSON。问题是数据为空,即 name
为空。这可以实现吗?
到目前为止我所拥有的:
Controller
public static void myMethod(String name) {
Logger.info(name);
}
路线文件
POST /test Application.myMethod
我发送带有 header Content-Type: application/json
的请求以及正文中的数据 {
"name": "一个名字"
}
最佳答案
我没有找到任何自动绑定(bind),所以我所做的是:
MyModel myModel = new GsonBuilder().create().fromJson(new InputStreamReader(request.body), MyModel.class);
效果非常好!
关于java - 是否可以让 Play Framework 1 处理 post 请求中发送的 JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18255035/