我是Play的新手,我想尝试从JSON帖子绑定一个String列表。
我执行以下操作:
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"
]
答案 0 :(得分:1)
此行会导致问题:
Form<Person> filledForm = PERSON.bind(request().body().asJson());
将其替换为:
Form<Person> filledForm = PERSON.bindFromRequest();