1. 程式人生 > >包含複雜型別的物件轉換json

包含複雜型別的物件轉換json

package cn.qtt.modules.bm.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.qtt.modules.bm.request.ActionInfo;
import cn.qtt.modules.bm.request.Activity;
import cn.qtt.modules.bm.request.Adaptation;
import cn.qtt.modules.bm.request.Condition;
import cn.qtt.modules.bm.request.Dictionary;
import cn.qtt.modules.bm.request.EnumData;
import cn.qtt.modules.bm.request.Extension;
import cn.qtt.modules.bm.request.MainActivity;
import cn.qtt.modules.bm.request.MainResource;
import cn.qtt.modules.bm.request.MainResourceStatisticsInfo;
import cn.qtt.modules.bm.request.ResourceInfo;
import cn.qtt.modules.bm.request.StrategyInfo;
import cn.qtt.modules.bm.request.Template;
import net.sf.json.JsonConfig;
import net.sf.json.processors.DefaultValueProcessor;

public class JsonConfigUtil extends JsonConfig {

	public JsonConfig jsonConfigUtil()  {
		JsonConfig jc = new JsonConfig();
		jc.registerDefaultValueProcessor(String.class,
				new DefaultValueProcessor() {

					@Override
					public Object getDefaultValue(Class arg0) {
						// TODO Auto-generated method stub
						return null;
					}
				});
		jc.registerDefaultValueProcessor(Long.class,
				new DefaultValueProcessor() {

					@Override
					public Object getDefaultValue(Class arg0) {
						// TODO Auto-generated method stub
						return null;
					}
				});
		jc.registerDefaultValueProcessor(Integer.class,
				new DefaultValueProcessor() {

					@Override
					public Object getDefaultValue(Class arg0) {
						// TODO Auto-generated method stub
						return null;
					}
				});
		jc.registerDefaultValueProcessor(List.class,
				new DefaultValueProcessor() {

					@Override
					public Object getDefaultValue(Class arg0) {
						// TODO Auto-generated method stub
						return null;
					}
				});
		return jc;
	}
	/**
	 * json裝換物件,且json中含有複雜型別使用,如list ,map等
	 * @return
	 */
	public Map jsonMap(){
		Map<String, Class> classMap = new HashMap<String, Class>();  
		classMap.put("mainActivitys", MainActivity.class);
		classMap.put("mainResources",MainResource.class);
		classMap.put("subActivitys",Activity.class);
		classMap.put("strategyInfoList",StrategyInfo.class);
		classMap.put("extensionList", Extension.class);
		classMap.put("template", Template.class);
		classMap.put("triggerEventList", Integer.class);
		classMap.put("adaptationList", Adaptation.class);
		classMap.put("dictionary", Dictionary.class);
		classMap.put("values", String.class);
		classMap.put("mrStatisticsInfo", MainResourceStatisticsInfo.class);
		classMap.put("value", Object.class);
		classMap.put("nestedAdaptationList", Adaptation.class);
		classMap.put("enumDataList", EnumData.class);
		classMap.put("condition", Condition.class);
		classMap.put("onSuccessed", ActionInfo.class);
		classMap.put("onFailed", ActionInfo.class);
		classMap.put("actionInfo", ActionInfo.class);
		classMap.put("resourceInfoList", ResourceInfo.class);
		classMap.put("subResourceList", ResourceInfo.class);
		return classMap;
	}
}