jax rs像param一样的多维数组

问题描述 投票:0回答:1

我在javascript中有下一个对象:

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

当我尝试解析查询时,params会产生如下结果:

customObj [0] [名称] =样品customObj [0] [其他] =&其他customObj [1] [名称] = SAMPLE2&customObj [1] [其他] =未分类产品

在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但我收到

错误的参数类型错误

.

multidimensional-array jax-rs queryparam
1个回答
0
投票

您可以接收String并将其解析为JsonObject。

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

请注意,这是javax.json

© www.soinside.com 2019 - 2024. All rights reserved.