0

我在 java 脚本中有下一个对象:

var customObj = [];
customObj[customId] = {name:'sample',other:'other'};
customObj[customId2] = {name:'sample2',other:'other2'};

当我尝试解析查询参数时,结果如下:

customObj[0][name]=sample&customObj[0][other]=other&customObj[1][name]=sample2&customObj[1][other]=other2

在 jax rs 我有这个资源:

@GET
public MyObject getSomething(@QueryParam("customObj") customObj /*Here is the problem*/){
  for(ObjectOrMapOrListOrArrayList myObject:customObject){
      System.out.println(myObject);//prints something like {name:'sample',other:'other'}
  }
}

但我不知道如何接收对象参数,我尝试使用 List> 因为在我的对象中所有数据都是字符串但它不起作用,我尝试使用 Map 但我接收

不正确的参数类型错误

.

4

1 回答 1

0

您可以接收字符串并将其解析为 JsonOnbject。

@GET
public MyObject getSomething(@QueryParam("customObj")String customObj ){
  JsonReader jsonReader = Json.createReader(new StringReader(customobj));
  JsonObject object = jsonReader.readObject();
  jsonReader.close();
  ...
}

请注意,这是javax.json

于 2018-03-03T08:27:08.823 回答