美文网首页
Json-lib转对象时过滤不需要的属性

Json-lib转对象时过滤不需要的属性

作者: LH_0811 | 来源:发表于2016-12-07 18:17 被阅读71次
        
            System.out.println("order:"+order);
            
            JsonConfig config = new JsonConfig();    
            config.setIgnoreDefaultExcludes(false);       
            config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);     
            config.setExcludes(new String[]{//只要设置这个数组,指定过滤哪些字段。    
               "id"
            });
            String param = JSONObject.fromObject(order, config).toString();
            System.out.println("param:"+param);
    
    ***
    
                     JsonConfig config = new JsonConfig();  
             config.setJsonPropertyFilter(new PropertyFilter()  
            {  
              @Override  
               public boolean apply(Object source, String name, Object value)  
                   {  
                   return value == null;  
               }  
            });  
            json.put("posUser", JSONObject.fromObject(posUserWithBLOBs,config).toString());
    
    

    相关文章

      网友评论

          本文标题:Json-lib转对象时过滤不需要的属性

          本文链接:https://www.haomeiwen.com/subject/cpqjmttx.html