java打印json数据类型_json-config

#json-config

oschina maven镜像构件:

com.tcshuo

json-config

1.0.0

json输出配置

{ignore:'c'}忽略复杂字段 {ignore:'n'} 不忽略字段 {ignore:'na'} 忽略不在allows允许列表的字段

{ignores:['dept','post']}凡在ignores的一律不输出 保证不输出dept、post字段

{allows:['id','name']}凡在allows的一律输出 保证输出字段id、name

{allows:['id','name'],ignore:'na'}只输出字段id、name {}默认:不输出复杂字段、集合或数组字段

{ignore:'c',allows:['dept']}除dept的复杂对象都不输出

{alias:{id:'value'}}字段别名输出,id字段输出为value字段

{ allows:['id','name','date','dept']

,childs :{

date:{format:'yyyy-MM-dd'}

,dept:{allows:['name']}

}

}输出id、name、date、dept、字段,其中date字段使用yyyy-MM-dd格式化

public void test1() {

HashMap map = new HashMap();

map.put("maptype", BeanType.A);

Bean beana = new Bean("bean a", BeanType.A);

Bean beanb = new Bean("bean b", BeanType.B);

map.put("beana", beana);

map.put("beanb", beanb);

ArrayList beanList = new ArrayList();

beanList.add(beana);

beanList.add(beanb);

map.put("beanList", beanList);

int[] intArray = new int[]{1, 2, 3};

map.put("intArray", intArray);

Bean[] beanArray = new Bean[]{beana, beanb};

map.put("beanArray", beanArray);

toJson(null, map);

toJson("{ignore:'n'}", map);

toJson("{ignore:'n'}", beanList);

toJson("{ignore:'na',allows:['name','date'],childs:{date:{format:'yyyy年MM月'}}}", beanList);

toJson("{ignore:'na',allows:['name','type'],childs:{type:{ignore:'na',allows:['javaEnumName']}}}", beanList);

toJson("{ignore:'na',allows:['name','type'],childs:{type:{alias:{javaEnumName:'NAME'},ignore:'na',allows:['javaEnumName']}}}", beanList);

}

private void toJson(String config, Object target) {

System.out.println(JsonConfigParser.parser(config, target).toJson());

}

Running com.tcshuo.json.config.SimpleTestCase

{"intArray":[1,2,3]}

{"beanb":{"name":"bean b"},"beanArray":[{"name":"bean a"},{"name":"bean b"}],"beana":{"name":"bean a"},"beanList":[{"name":"bean a"},{"name":"bean b"}],"intArray":[1,2,3],"maptype":{"declaringClass":"com.tcshuo.json.config.BeanType","name":"a","value":0,"javaEnumName":"A"}}

[{"name":"bean a","type":{"declaringClass":"com.tcshuo.json.config.BeanType","name":"a","value":0,"javaEnumName":"A"},"date":"2015-05-06 18:57:15"},{"name":"bean b","type":{"declaringClass":"com.tcshuo.json.config.BeanType","name":"b","value":1,"javaEnumName":"B"},"date":"2015-05-06 18:57:15"}]

[{"name":"bean a","date":"2015年05月"},{"name":"bean b","date":"2015年05月"}]

[{"name":"bean a","type":{"javaEnumName":"A"}},{"name":"bean b","type":{"javaEnumName":"B"}}]

[{"name":"bean a","type":{"NAME":"A"}},{"name":"bean b","type":{"NAME":"B"}}]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值