我有UI将JSON对象发送到后端(java)。当JSON太大时,JSON对象有时会为null
@Transactional
public static Result save() {
try {
JsonNode json = request().body().asJson();
if (json == null) {
return ok(SEND_JSON_OBJECT);
}
} catch (Exception e) {}
}
当JSON很大时我得到null
答案 0 :(得分:3)
您需要通过覆盖该控制器操作的JSON正文解析器的默认设置来增加最大内容长度:http://www.playframework.com/documentation/2.2.x/JavaBodyParsers
来自文档:
// Accept only 10KB of data.
@BodyParser.Of(value = BodyParser.Text.class, maxLength = 10 * 1024)
public static Result index() {
if(request().body().isMaxSizeExceeded()) {
return badRequest("Too much data!");
} else {
return ok("Got body: " + request().body().asText());
}
}