【问题标题】:Play framework JSON list binding播放框架 JSON 列表绑定
【发布时间】:2015-08-05 09:38:48
【问题描述】:

我是 Play 新手,我想尝试从 JSON 帖子中绑定一个字符串列表。

我执行以下操作:

import play.data.validation.Constraints;
import java.util.ArrayList;
import java.util.List;

Form<Person> PERSON = new Form<>(Person.class);
Form<Person> filledForm = PERSON.bind(request().body().asJson());

Person class {

  @Constraints.Required
  @Constraints.Email
  private String email;

  @Constraints.Required
  private List<String> adresses = new ArrayList<>();

}

我收到以下消息:

"matches":[
"This field is required"
]

【问题讨论】:

    标签: java json playframework playframework-2.0


    【解决方案1】:

    这行会导致问题:

    Form<Person> filledForm = PERSON.bind(request().body().asJson());
    

    替换为:

    Form<Person> filledForm = PERSON.bindFromRequest();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      相关资源
      最近更新 更多