spring controller json收到json List

com*_*tta 2 java rest spring json jackson

我在json包含下面发帖子

{"testListObject":[{"testText":"bbb","testDate":"02.01.2011 00:00:00.000"},{"testText":"aaa","testDate":"01.01.2011 00:00:00.000"}]}
Run Code Online (Sandbox Code Playgroud)

在我的春季控制器中我有

@RequestMapping(value = "/post/tester/", method = RequestMethod.POST)
 public @ResponseBody String postItinerary(@ModelAttribute("testListObject") TestList testList) throws IOException {


    System.out.println("1="+testList); //ok
    System.out.println("2="+testList.childListObject); //print null
}
Run Code Online (Sandbox Code Playgroud)

知道为什么我为List childListObject获取null?

我的pojo看起来像下面

    public class TestList (){

    public List<ChildObject> childListObject;

//get and set
    }


    public class ChildObject(){

    public String testText;
    public String testDate;
//get and set    
}
Run Code Online (Sandbox Code Playgroud)

Aff*_*ffe 5

@ModelAttribute调用Web数据绑定器.它正在寻找普通的post方法参数(例如,param key - "childListObject [0] .testText"param value"bbb")来绑定到你的对象上.
要将JSON反序列化为对象,您需要使用它@RequestBody来调用序列化程序.

此外,您的JSON似乎与obect不匹配.You JSON只是一个没有包装器对象的数组,因此如果您将其作为请求提交,则method参数将只是一个List.