简体   繁体   English

JSON地图 <String,ArrayList> 数据没有在宁静的球衣中转换为bean对象

[英]JSON Map<String,ArrayList> data is not converting into bean object in restful jersey

There is a Ajax call with JSON data of String, Array and Map. 使用String,Array和Map的JSON数据进行Ajax调用。 I am able to get String and Array data after converting into DashboardChartData (a Bean class) in jersey but not able to get Map values. 在转换为泽西的DashboardChartData (Bean类)但无法获取Map值后,我能够获取String和Array数据。 suppose bean is the object of DashboardChartData and globalInFilters is a data member of DashboardChartData Class and make setter/getter as same then bean.getGlobalInFilters(); 假设bean是DashboardChartData的对象,globalInFilters是DashboardChartData类的数据成员,并使setter / getter与bean相同,然后是bean.getGlobalInFilters(); is getting null not desired value. 得到null不是期望的值。

Code is: 代码是:

        function demo(){
           var dashbord = {
          "aoId": "M_AO_918",
          "viewBys": ["Brand", "Category", "State"],
          "viewIds": ["615228", "615128", "614847"],
          "dimensions": ["615228"],
          "aggregation": ["SUM", "SUM", "SUM", "SUM", "SUM", "SUM"],
          "meassures": ["Gross Sales", "Net Sales", "Discount Amt", "Discount%",  "Net Margin Amt", "Gross Margin Amt"],
          "meassureIds": ["616275", "616283", "616279", "616648", "616295", "616303"],
          "globalInFilters": {"615228": ["Lenovo", "Apple"]}
                        };

                        $("#query").html(JSON.stringify(dashbord));
                        $.ajax({
                            type: "POST",
                            contentType: "application/json; charSet=UTF-8",
                            dataType: "json",
                            data: JSON.stringify(dashbord),
                            url: "<%=request.getContextPath()%>/webresources/solrservice/test1",
                             success: function(data, textStatus, jqXHR){
                    alert('Bean created successfully');

                },
                error: function(jqXHR, textStatus, errorThrown){
                    alert('Bean error: ' + textStatus);
                }
                        });
            }    

I have created DashboardChartData class with above parameter including: 我用上面的参数创建了DashboardChartData类,包括:

    private Map<String, List<String>> globalInFilters;

  public Map<String, List<String>> getGlobalInFilters() {
        return globalInFilters;
    }

    public void setGlobalInFilters(Map<String, List<String>> globalInFilters) {
        this.globalInFilters = globalInFilters;
    }


         @Path("/test1")
            @POST
            @Consumes(MediaType.APPLICATION_JSON)
            @Produces(MediaType.APPLICATION_JSON)
            public void setData1(DashboardChartDataBean bean) throws Exception {
                bean.getGlobalInFilters(); //getting null 
                 ProgenSolrDao daoObj = new ProgenSolrDao();

                try {
                    QueryResponse response = daoObj.executeSolrQuery("city",bean);
                } catch (Exception e) {

                }

            }

bean.getGlobalInFilters() gets null , except this all other values is getting fine. bean.getGlobalInFilters()获取null ,除非所有其他值都正常。 please help how I can get the values of globalInFilters . 请帮助我如何globalInFilters的值。

Why are you stringifying before sending it. 为什么在发送之前进行字符串化。 Try without stringify. 尝试不使用stringify。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM