JSONObjec序列化对象过滤为null的属性

 

 

 

    @Test
    public void test3() {
        PgwReqtBody3002 pgwReqtBody3002 = new PgwReqtBody3002();
        pgwReqtBody3002.setService("1");

        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
            @Override
            public boolean apply(Object obj, String key, Object value) {
                if (value == null) {
                    return true;
                }
                return false;
            }
        });
        JSONObject j = JSONObject.fromObject(pgwReqtBody3002, jsonConfig);

        System.out.println(j.toString());

    }

 

posted @ 2017-05-11 16:38  crazyYong  阅读(6226)  评论(0编辑  收藏  举报