当Json在Play Framework中太大时,Json会变为null

时间:2014-05-23 15:57:24

标签: java playframework-2.0

我有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

1 个答案:

答案 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()); 
  }
}