Play framework JSON list binding

2019-08-12 10:19发布

I am new into Play, and I want to try to bind a List of String from a JSON post.

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"
]

1条回答
男人必须洒脱
2楼-- · 2019-08-12 10:45

This line causes problems:

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

Replace it with:

Form<Person> filledForm = PERSON.bindFromRequest();
查看更多
登录 后发表回答