1

我有一个 JSON 格式

var array1 = 新数组;
var array2 = 新数组;
//将一些字符串推送到array1和array2
var data = JSON.stringify({'email':email,'age':age,'array1':array1,'array2':array2});

我如何使用 Jackson JSON Mapper 将其映射到 POJO 以避免 400 Bad Request。

我试过了

公共类 MyPOJOs{
  私人字符串电子邮件;
  私有字符串年龄;
  私人 MyList 数组1;
  私人 MyList 数组2;
  //getter 和 setter
}
公共类 MyList{
  私有 ArrayList 列表;
  //getter 和 setter
}

我的控制器

公共 @ResponseBody 响应 myController(@RequestBody MyPOJOs myPOJOs){
   字符串电子邮件 = myPOJOs.getEmail();
   logger.log("嗨" + 电子邮件);
   返回空值;
}

谢谢。

4

1 回答 1

1

I do not really know Jackson JSON processor but I would be surprised that it is able to map your arrays to your custom MyList objects.

I would expect the MyPOJOs class to have member like private String[] array1 or private List<String> array1 or a Collection.

btw: There are many mistakes in your code that make me think you do not post real code here. Misspelled type names etc.

于 2012-08-16T14:35:26.263 回答