我想发送java.util.Map<String, Object>
作为JAX-RS JSON参数的一部分,
我有以下情况:
@Path("/banner")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class BannerImageService extends BaseServiceFacade<BannerImage, Integer> {
...
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<T> query(MapRequestBeanVO mapRequestBeanVO) {
try {
return getService().search(mapRequestBeanVO.getQuery(), mapRequestBeanVO.getParams());
} catch (ServiceException e) {
serviceException(e);
} catch (Exception ex) {
logException(ex);
}
return null;
}
...
public class MapRequestBeanVO extends BaseSemanticNamedVO<Integer> {
private String query;
private Map<String, Object> params;
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
public Map<String, Object> getParams() {
return params;
}
public void setParams(Map<String, Object> params) {
this.params = params;
}
}
我目前正在为JAX-RS运行Glassfish4 Jersey实现 我应该包括第三方lib来做这项工作(Moxy - Jackson)吗?或者JAXB会处理它吗?什么是最好的选择?
答案 0 :(得分:0)
我找到的最佳方法是让所有对象都使用字符串,然后在需要时在服务器端对其进行相应处理,以便类更改为:
public class MapRequestBeanVO extends BaseSemanticNamedVO<String> {
private String query;
private Map<String, String> params;
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
public Map<String, Object> getParams() {
return params;
}
public void setParams(Map<String, Object> params) {
this.params = params;
}
}