`
aiyanbo
  • 浏览: 64256 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

json配置相关

    博客分类:
  • java
阅读更多

介于目前JsonConfig中没有setIncludes(..)方法,所以自己写了个:

 

 

 

package com.aiy.util;

/**
 * @author aiyanbo
 */
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;

import net.sf.json.JsonConfig;

public class Util{
    //返回一个JsonConfig对象
	public static JsonConfig setIncludes(Class c,String...p){
		JsonConfig config=new JsonConfig();
		Set<String> set=new HashSet<String>();
		Field[] fs=c.getDeclaredFields();
		for (Field f : fs) {
			set.add(f.getName());
		}
		if(p!=null){
			for(String str : p){
				set.remove(str);
			}
		}
		String[] str=new String[set.size()];
		config.setExcludes(set.toArray(str));
		return config;
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics