如何将javascript数组放在类对象的arraylist中?

时间:2018-05-10 19:48:19

标签: javascript java angularjs spring

我有以下代码:

广告类:

public class Advertisement {
    String name;
    String description;
    Date date;
    String city;
    String type;
    int rooms;
    int surface;
    int price;
    int userID;
    ArrayList<String> images;
    int httpStatus;
}

广告弹簧控制器:

 @RequestMapping(value = "/post", method = RequestMethod.POST)
    public boolean postAds(@RequestBody Advertisement newAd) {
        System.out.println(newAd.name+" "+" "+newAd.rooms+" "+newAd.surface+" "+newAd.price+" " + newAd.type+" "+newAd.description+newAd.images);

        return true;
    }

角度控制器:

$http({
  method: 'POST',
  url: AppSettings.getApiUrl('/post'),
  data: {
    name: $scope.form.name,
    description: $scope.form.description,
    //city: $scope.form.city,
    rooms: $scope.form.rooms,
    surface: $scope.form.surface,
    price: $scope.form.price,
    type: $scope.form.selected,
    images: $scope.images,
    //userId: localStorage.getItem('token'),
  }

现在,当我向服务器发出post请求时,它会出现以下错误:

  

JSON解析错误:无法从START_ARRAY标记中反序列化java.lang.String的实例;嵌套异常

我应该如何将$ scope.images数组反序列化为图像?

0 个答案:

没有答案