Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Play framework 2.5 Json post请求绑定器_Java_Json_Playframework_Playframework 2.0_Playframework 2.5 - Fatal编程技术网

Java Play framework 2.5 Json post请求绑定器

Java Play framework 2.5 Json post请求绑定器,java,json,playframework,playframework-2.0,playframework-2.5,Java,Json,Playframework,Playframework 2.0,Playframework 2.5,我有一门课,内容如下: public class NoteForm { public Integer id; @Constraints.Required public Integer userId; @Constraints.Required public String note; // cant get any of the following to work public Int[] tags; public

我有一门课,内容如下:

public class NoteForm {
    public Integer id;

    @Constraints.Required
    public Integer userId;    

    @Constraints.Required
    public String  note;

    // cant get any of the following to work
    public Int[] tags; 
    public String[] tags;
    public List<int> tags;
}
我无法绑定窗体的tag属性,我做错了什么

我目前正在使用以下代码解决此问题,但无法使用表单帮助器使用Play framework验证:

NoteForm note = Json.fromJson(json, NoteForm.class);

我能够通过以下方式完成这项工作:

公共列表标签

并且具有如下形式的绑定:

@BodyParser.Of(BodyParser.Json.class)
public Result updateNote(){
    Form<NoteForm> noteForm = NOTE_FORM.bind(request().body().asJson());

    //also have tried the following
    //Form<NoteForm> noteForm = NOTE_FORM.bindFromRequest();

    if(noteForm.hasErrors()){
        return badRequest(noteForm.errorsAsJson());
    }else{
        noteService.saveNote(noteForm.get());
        return jsonResult(ok(Json.toJson("Save Succeeded")));
    }
}
Form<NoteForm> noteForm = formFactory.form(NoteForm.class).bind(request().body().asJson());

奇怪的不
列出标签也失败了?只是尝试了一下,但没有成功。你不缺少getter和setter吗?您是否设置了内容类型:application/json header?请看下面的链接@Sivakumar我在发布之前确实查看了这个问题,如果您查看了我发布的代码,我的评论表明我尝试了与您链接的帖子相同的操作//表单noteForm=NOTE_Form.bindFromRequest();
Form<NoteForm> noteForm = formFactory.form(NoteForm.class).bind(request().body().asJson());
Form(of=class models.NoteForm, data={note=adsfadsfdsaaf, id=1, tags[1]=6, userId
=1, tags[0]=5}, value=Optional[models.NoteForm@5cd20029], errors={})