简体   繁体   English

播放框架JSON列表绑定

[英]Play framework JSON list binding

I am new into Play, and I want to try to bind a List of String from a JSON post. 我是Play的新手,我想尝试绑定JSON帖子中的字符串列表。

I do the following: 我执行以下操作:

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<>();

}

I get the following message: 我收到以下消息:

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

This line causes problems: 这行会导致问题:

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

Replace it with: 替换为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM