gpt4 book ai didi

java - Play框架JSON列表绑定(bind)

转载 作者:行者123 更新时间:2023-11-30 08:01:41 25 4
gpt4 key购买 nike

我是 Play 新手,我想尝试从 JSON 帖子绑定(bind)字符串列表。

我执行以下操作:

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

最佳答案

此行会导致问题:

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

替换为:

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

关于java - Play框架JSON列表绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31828748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com