我想发送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实现
我是否应该包括第三方库来做这项工作(Moxy-Jackson)?还是JAXB会处理?最好的选择是什么?

最佳答案

我发现的最佳方法是让所有对象都具有字符串,然后在需要时在服务器端对它们进行相应的处理,这样该类将变为:

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;
    }
}

10-02 22:47