net.sf.json.JsonConfig Java Examples

The following examples show how to use net.sf.json.JsonConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QuestionManageAction.java    From OnLineTest with Apache License 2.0 6 votes vote down vote up
public String getChoice(){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=utf-8");
	Choice choice = new Choice();
	choice.setChoiceId(choiceId);
	Choice newChoice = questionService.getChoiceById(choice);
	JsonConfig jsonConfig = new JsonConfig();
	jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
	    public boolean apply(Object obj, String name, Object value) {
		if(obj instanceof Set||name.equals("subjects") || name.equals("choices") || name.equals("judges")){//过滤掉集合
			return true;
		}else{
			return false;
		}
	   }
	});
	
	JSONObject jsonObject = JSONObject.fromObject(newChoice,jsonConfig);
	try {
		response.getWriter().print(jsonObject);
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
Example #2
Source File: ForfeitManageAction.java    From LibrarySystem with Apache License 2.0 6 votes vote down vote up
public String  getForfeitInfoById(){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=utf-8");
	ForfeitInfo forfeitInfo = new ForfeitInfo();
	forfeitInfo.setBorrowId(borrowId);
	ForfeitInfo  newForfeitInfo = forfeitService.getForfeitInfoById(forfeitInfo);
	JsonConfig jsonConfig = new JsonConfig();
	jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
	    public boolean apply(Object obj, String name, Object value) {
		if(obj instanceof Authorization||name.equals("authorization") || obj instanceof Set || name.equals("borrowInfos")){	
			return true;
		}else{
			return false;
		}
	   }
	});
	
	
	JSONObject jsonObject = JSONObject.fromObject(newForfeitInfo,jsonConfig);
	try {
		response.getWriter().print(jsonObject);
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
Example #3
Source File: UsergroupClient.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ユーザグループ情報を更新します。
 * usrgrpidパラメータを必ず指定する必要があります。<br/>
 * @param param {@link UsergroupUpdateParam}
 * @return 更新されたユーザグループ情報のusrgrpidのリスト
 */
@SuppressWarnings("unchecked")
public List<String> update(UsergroupUpdateParam param) {
    if (param.getUsrgrpid() == null || param.getUsrgrpid().length() == 0) {
        throw new IllegalArgumentException("usrgrpid is required.");
    }

    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    if (accessor.checkVersion("2.0") >= 0) {
        // api_accessは2.0以降で廃止されたパラメータ
        if (params.containsKey("api_access")) {
            params.remove("api_access");
        }
    }

    JSONObject result = (JSONObject) accessor.execute("usergroup.update", params);

    JSONArray usrgrpids = result.getJSONArray("usrgrpids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);
    return (List<String>) JSONArray.toCollection(usrgrpids, config);
}
 
Example #4
Source File: BaseAction.java    From xmu-2016-MrCode with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 把Object转抱成Json时更改数据的默认转换格式
 * @param o 
 * @param otherParams 其它参数
 * @param excludes 不进行序列化属�?的名�?
 */
public void writeJsonToResponseWithDataFormat(Object o, Map<String, Object> otherParams, String excludes[]) {
	JsonConfig config = new JsonConfig();
	//更改Date类型转成json数据的格式化形式
	config.registerJsonValueProcessor(Date.class, new JsonValueFormat());
	config.setExcludes(excludes);// 除去dept属�?
	HashMap<String, Object> tempMap = new HashMap<String, Object>();
	tempMap.put("Model", o);
	if (otherParams != null) {
		Iterator<Entry<String, Object>> iter = otherParams.entrySet()
				.iterator();
		while (iter.hasNext()) {
			Entry<String, Object> entry = iter.next();
			tempMap.put(entry.getKey(), entry.getValue());
		}
	}
	JSONObject json = JSONObject.fromObject(tempMap, config);
	writeStringToResponse(json.toString().replaceAll("null", "[]"));
	
}
 
Example #5
Source File: BackManageAction.java    From LibrarySystem with Apache License 2.0 6 votes vote down vote up
public String  getBackInfoById(){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=utf-8");
	BackInfo backInfo = new BackInfo();
	backInfo.setBorrowId(borrowId);
	BackInfo newBackInfo = backService.getBackInfoById(backInfo);
	JsonConfig jsonConfig = new JsonConfig();
	jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
	    public boolean apply(Object obj, String name, Object value) {
		if(obj instanceof Authorization||name.equals("authorization") || obj instanceof Set || name.equals("borrowInfos")){	
			return true;
		}else{
			return false;
		}
	   }
	});
	
	
	JSONObject jsonObject = JSONObject.fromObject(newBackInfo,jsonConfig);
	try {
		response.getWriter().print(jsonObject);
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
Example #6
Source File: BaseAction.java    From xmu-2016-MrCode with GNU General Public License v2.0 6 votes vote down vote up
public void writeJsonToResponse(Object o, Map<String, Object> otherParams) {
	JsonConfig config = new JsonConfig();
	config.setExcludes(new String[] { "addTime" });// 除去dept属�?
	HashMap<String, Object> tempMap = new HashMap<String, Object>();
	tempMap.put("Model", o);
	if (otherParams != null) {
		Iterator<Entry<String, Object>> iter = otherParams.entrySet()
				.iterator();
		while (iter.hasNext()) {
			Entry<String, Object> entry = iter.next();
			tempMap.put(entry.getKey(), entry.getValue());
		}
	}
	JSONObject json = JSONObject.fromObject(tempMap, config);
	writeStringToResponse(json.toString());
}
 
Example #7
Source File: UsergroupClient.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ユーザグループ情報とユーザ情報、権限情報を紐付けます。
 * userids,usrgrpidsパラメータを必ず指定する必要があります。<br/>
 * @param param {@link UsergroupMassAddParam}
 * @return 更新されたユーザグループ情報のusrgrpidのリスト
 */
public List<String> massAdd(UsergroupMassAddParam param) {
    if (param.getUserids() == null || param.getUserids().isEmpty()) {
        throw new IllegalArgumentException("userids is required.");
    }
    if (param.getUsrgrpids() == null || param.getUsrgrpids().isEmpty()) {
        throw new IllegalArgumentException("usrgrpids is required.");
    }
    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    JSONObject result = (JSONObject) accessor.execute("usergroup.massAdd", params);

    JSONArray usrgrpids = result.getJSONArray("usrgrpids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);

    // Zabbix 2.2.9でusrgrpidsが数値のArrayとして返ってくることへの対応
    List<?> ids = (List<?>) JSONArray.toCollection(usrgrpids, config);
    List<String> resultIds = new ArrayList<String>();
    for (Object id : ids) {
        resultIds.add(id.toString());
    }
    return resultIds;
}
 
Example #8
Source File: SubjectManageAction.java    From OnLineTest with Apache License 2.0 6 votes vote down vote up
public String getSubject(){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=utf-8");
	Subject subject = new Subject();
	subject.setSubjectId(subjectId);
	Subject newSubject = subjectService.getSubjectById(subject);
	JsonConfig jsonConfig = new JsonConfig();
	jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
	    public boolean apply(Object obj, String name, Object value) {
		if(obj instanceof Set||name.equals("subjects") || name.equals("choices") || name.equals("judges")){//过滤掉集合
			return true;
		}else{
			return false;
		}
	   }
	});
	
	JSONObject jsonObject = JSONObject.fromObject(newSubject,jsonConfig);
	try {
		response.getWriter().print(jsonObject);
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
Example #9
Source File: CourseManageAction.java    From OnLineTest with Apache License 2.0 6 votes vote down vote up
public String getAllCourses(){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=utf-8");
	List<Course> allCourses = courseService.getAllCourses();
	JsonConfig jsonConfig = new JsonConfig();
	jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
	    public boolean apply(Object obj, String name, Object value) {
		if(obj instanceof Set||name.equals("subjects")){//过滤掉集合
			return true;
		}else{
			return false;
		}
	   }
	});
	
	
	String json = JSONArray.fromObject(allCourses,jsonConfig).toString();//List------->JSONArray
	try {
		response.getWriter().print(json);
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
Example #10
Source File: BlazeMeterHttpUtils.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Override
protected String extractErrorMessage(String response) {
    if (response != null && !response.isEmpty()) {
        try {
            JSON jsonResponse = JSONSerializer.toJSON(response, new JsonConfig());
            if (jsonResponse instanceof JSONObject) {
                JSONObject object = (JSONObject) jsonResponse;
                JSONObject errorObj = object.getJSONObject("error");
                if (errorObj.containsKey("message")) {
                    return errorObj.getString("message");
                }
            }
        } catch (JSONException ex) {
            log.debug("Cannot parse JSON error response: " + response);
        }
    }
    return response;
}
 
Example #11
Source File: ZabbixClient.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
protected JsonConfig createDefaultConfig() {
    JsonConfig config = new JsonConfig();
    PropertyNameProcessorMatcher matcher = new PropertyNameProcessorMatcher() {
        @Override
        @SuppressWarnings("rawtypes")
        public Object getMatch(Class target, Set set) {
            Object key = DEFAULT.getMatch(target, set);
            if (key == null) {
                key = Object.class;
            }
            return key;
        }
    };
    config.setJavaPropertyNameProcessorMatcher(matcher);
    config.setJsonPropertyNameProcessorMatcher(matcher);
    config.registerJavaPropertyNameProcessor(Object.class, new JavaPropertyNameProcessor());
    config.registerJsonPropertyNameProcessor(Object.class, new JsonPropertyNameProcessor());
    config.setJsonPropertyFilter(new NullPropertyFilter());
    return config;
}
 
Example #12
Source File: GoodsAction.java    From xxshop with Apache License 2.0 6 votes vote down vote up
/**
	 * goodsIds用来接收来自前台的数据:包含了categoryId和num的json字符串
	 * result 则返回查询到的信息,也是封装成了一个json字符串
	 * @param goodsIds
	 * @param model
	 * @return
	 */
	@RequestMapping("/getGoodsesByIds")
	public String getGoodsesByIds(String goodsIds, Model model) {
//		System.out.println("goodsIds:" + goodsIds);
		String[] ids = goodsIds.split(",");
//		for (String s : ids) {
//			System.out.println("test:" + s);
//		}
//		System.out.println("test:" + ids.toString());
		List<Goods> goodses = goodsService.getGoodsByIds(ids);
		JsonConfig c = new JsonConfig();
		c.setExcludes(new String[] { "category", "goodsNo", "categoryId",
				"price1", "stock", "description", "role", "sellTime",
				"sellNum", "score" });
		JSONArray a = JSONArray.fromObject(goodses, c);
		String result = a.toString();
		model.addAttribute("result", result);
		System.out.println(result);
//		System.out.println("result:" + result);
		return "/TestJSP.jsp";
//		return "getgoodsesbyids";

	}
 
Example #13
Source File: QuestionManageAction.java    From OnLineTest with Apache License 2.0 6 votes vote down vote up
public String getJudge(){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=utf-8");
	Judge judge = new Judge();
	judge.setJudgeId(judgeId);
	Judge newJudge = questionService.getJudgeById(judge);
	JsonConfig jsonConfig = new JsonConfig();
	jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
	    public boolean apply(Object obj, String name, Object value) {
		if(obj instanceof Set||name.equals("subjects") || name.equals("choices") || name.equals("judges")){//过滤掉集合
			return true;
		}else{
			return false;
		}
	   }
	});
	
	JSONObject jsonObject = JSONObject.fromObject(newJudge,jsonConfig);
	try {
		response.getWriter().print(jsonObject);
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
Example #14
Source File: AuthorizationAction.java    From LibrarySystem with Apache License 2.0 6 votes vote down vote up
public String getAuthorization(){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=utf-8");
	Authorization authorization = new Authorization();
	authorization.setAid(id);
	Authorization newAuthorization = authorizationService.getAuthorizationByaid(authorization);
	JsonConfig jsonConfig = new JsonConfig();
	jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
	    public boolean apply(Object obj, String name, Object value) {
		if(obj instanceof Admin || name.equals("admin")){//过滤掉Authorization中的admin
			return true;
		}else{
			return false;
		}
	   }
	});
	
	JSONObject jsonObject = JSONObject.fromObject(newAuthorization,jsonConfig);
	try {
		response.getWriter().print(jsonObject);
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
Example #15
Source File: BorrowAction.java    From LibrarySystem with Apache License 2.0 6 votes vote down vote up
public String  getBackInfoById(){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=utf-8");
	BackInfo backInfo = new BackInfo();
	backInfo.setBorrowId(borrowId);
	BackInfo newBackInfo = backService.getBackInfoById(backInfo);
	JsonConfig jsonConfig = new JsonConfig();
	jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
	    public boolean apply(Object obj, String name, Object value) {
		if(obj instanceof Authorization||name.equals("authorization") || obj instanceof Set || name.equals("borrowInfos")){	
			return true;
		}else{
			return false;
		}
	   }
	});
	
	
	JSONObject jsonObject = JSONObject.fromObject(newBackInfo,jsonConfig);
	try {
		response.getWriter().print(jsonObject);
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
Example #16
Source File: HostgroupClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ホストグループ情報を更新します。<br/>
 * groupidパラメータを必ず指定する必要があります。<br/>
 * 存在しないgroupidを指定した場合、例外をスローします。<br/>
 *
 * @param param {@link HostgroupUpdateParam}
 * @return 更新したホストグループ情報のhostgroupidのリスト
 */
@SuppressWarnings("unchecked")
public List<String> update(HostgroupUpdateParam param) {
    if (param.getGroupid() == null) {
        throw new IllegalArgumentException("groupid is required.");
    }
    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    JSONObject result = (JSONObject) accessor.execute("hostgroup.update", params);

    JSONArray hostgroupids = result.getJSONArray("groupids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);
    return (List<String>) JSONArray.toCollection(hostgroupids, config);
}
 
Example #17
Source File: HostgroupClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ホストグループ情報を作成します。<br/>
 * nameパラメータを必ず指定する必要があります。<br/>
 * 既に存在するホストのnameを指定した場合、例外をスローします。
 *
 * @param param {@link HostgroupCreateParam}
 * @return 作成されたホストグループ情報のhostgroupidのリスト
 */
@SuppressWarnings("unchecked")
public List<String> create(HostgroupCreateParam param) {
    if (param.getName() == null || param.getName().length() == 0) {
        throw new IllegalArgumentException("name is required.");
    }
    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    JSONObject result = (JSONObject) accessor.execute("hostgroup.create", params);

    JSONArray hostgroupids = result.getJSONArray("groupids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);
    return (List<String>) JSONArray.toCollection(hostgroupids, config);
}
 
Example #18
Source File: MenuManagerController.java    From jeewx with Apache License 2.0 5 votes vote down vote up
@RequestMapping(params = "getSubMenu")
public void getSubMenu(HttpServletRequest request,
		HttpServletResponse response) {
	String accountid = ResourceUtil.getWeiXinAccountId();
	String msgType = request.getParameter("msgType");
	String resMsg = "";
	 JsonConfig config = new JsonConfig();
	 config.setJsonPropertyFilter(new PropertyFilter(){  
		    public boolean apply(Object source, String name, Object value) {  
		        if(name.equals("menuList")) { //要过滤的areas ,Map对象中的  
		            return true;  
		        } else {  
		            return false;  
		        }  
		    }  
		});
		List<MenuEntity> textList = this.weixinMenuService
				.findByQueryString("from MenuEntity t  where t.accountId = '"
						+  accountid+ "'");
		JSONArray json = JSONArray.fromObject(textList,config);
		resMsg = json.toString();

	try {
		response.setCharacterEncoding("utf-8");
		PrintWriter writer = response.getWriter();
		writer.write(resMsg);
		writer.flush();
		writer.close();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example #19
Source File: HostgroupClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ホストグループ情報を取得します。<br/>
 * ホストグループ情報が存在しない場合、空のリストを返します。
 *
 * @param param {@link HostgroupGetParam}
 * @return 取得したホストグループ情報のリスト
 */
@SuppressWarnings("unchecked")
public List<Hostgroup> get(HostgroupGetParam param) {
    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    JSONArray result = (JSONArray) accessor.execute("hostgroup.get", params);

    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(Hostgroup.class);
    return (List<Hostgroup>) JSONArray.toCollection(result, config);
}
 
Example #20
Source File: ProxyClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * プロキシ情報を取得します。<br/>
 * プロキシ情報が存在しない場合、空のリストを返します。
 *
 * @param param {@link ProxyGetParam}
 * @return 取得したプロキシ情報のリスト
 */
@SuppressWarnings("unchecked")
public List<Proxy> get(ProxyGetParam param) {
    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    JSONArray result = (JSONArray) accessor.execute("proxy.get", params);

    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(Proxy.class);
    return (List<Proxy>) JSONArray.toCollection(result, config);
}
 
Example #21
Source File: AbstractStrutsAction.java    From zxl with Apache License 2.0 5 votes vote down vote up
protected JsonConfig jsonConfigForPageData(Class<?> clazz) {
	try {
		return CycleSupport.class.isAssignableFrom(clazz) ? ((CycleSupport) clazz.newInstance()).jsonConfig() : null;
	} catch (Exception e) {
		LogUtil.warn(LOGGER, "new instance error", e);
		return null;
	}
}
 
Example #22
Source File: JsonUtil.java    From SmartEducation with Apache License 2.0 5 votes vote down vote up
public static JSONArray jsonListFilter(List objList, String[] filterNames){
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setIgnoreDefaultExcludes(false);    
    jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);    //防止自包含 
    //jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class, new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss")); 
    if(filterNames != null){
        //这里是核心,过滤掉不想使用的属性
        jsonConfig .setExcludes(filterNames) ;
    }
    JSONArray jsonArray = JSONArray.fromObject(objList, jsonConfig);
    return jsonArray;
}
 
Example #23
Source File: JsonUtil.java    From SmartEducation with Apache License 2.0 5 votes vote down vote up
public static JSONObject jsonFilter(Object obj, String[] filterNames){
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setIgnoreDefaultExcludes(false);    
    jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);    //防止自包含
    
    if(filterNames != null){
        //这里是核心,过滤掉不想使用的属性
        jsonConfig .setExcludes(filterNames) ;
    }
    JSONObject jsonObj = JSONObject.fromObject(obj, jsonConfig);
    return jsonObj;
}
 
Example #24
Source File: HostgroupClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ホストグループ情報を削除します。<br/>
 * groupidパラメータを必ず指定する必要があります。<br/>
 * 存在しないgroupidを指定した場合、例外をスローします。<br/>
 *
 * @param groupids 削除するホストグループのIDのリスト
 * @return 削除したホストグループ情報のhostgroupidのリスト
 */
@SuppressWarnings("unchecked")
public List<String> delete(List<String> groupids) {
    if (groupids == null || groupids.isEmpty()) {
        throw new IllegalArgumentException("groupid is required.");
    }

    JSONArray params;
    if (accessor.checkVersion("2.0") < 0) {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        for (String groupid : groupids) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("groupid", groupid);
            list.add(map);
        }
        params = JSONArray.fromObject(list, defaultConfig);
    } else {
        params = JSONArray.fromObject(groupids, defaultConfig);
    }

    JSONObject result = (JSONObject) accessor.execute("hostgroup.delete", params);

    JSONArray hostgroupids = result.getJSONArray("groupids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);
    return (List<String>) JSONArray.toCollection(hostgroupids, config);
}
 
Example #25
Source File: CommonUtil.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
/**
 * 直接输出JSON.含有java.sql.date数据类型
 * 
 * @param response
 * @param object
 * @param headers
 */
public static void renderJsonForSqlDate(final HttpServletResponse response, final Object object,
		final String... headers) {
	JsDateJsonBeanProcessor beanProcessor = new JsDateJsonBeanProcessor();
	JsonConfig config = new JsonConfig();
	config.registerJsonBeanProcessor(java.sql.Date.class, beanProcessor);
	JSONObject json = JSONObject.fromObject(object, config);
	render(response, JSON, json.toString(), headers);
}
 
Example #26
Source File: JsonValueFormat.java    From xmu-2016-MrCode with GNU General Public License v2.0 5 votes vote down vote up
public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2) {
	// TODO Auto-generated method stub
	if(arg1 instanceof Timestamp){
		   String format=new SimpleDateFormat(pattern).format(arg1);
		   return format;
	}
	return null;
}
 
Example #27
Source File: HostClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ホスト情報を削除します。<br/>
 * hostidパラメータを必ず指定する必要があります。<br/>
 * 存在しないhostidを指定した場合、例外をスローします。<br/>
 *
 * @param hostids 削除するホストIDのリスト
 * @return 削除したホスト情報のhostidのリスト
 */
@SuppressWarnings("unchecked")
public List<String> delete(List<String> hostids) {
    if (hostids == null || hostids.isEmpty()) {
        throw new IllegalArgumentException("hostid is required.");
    }

    List<?> param;
    if (accessor.checkVersion("3.0.0") < 0) {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        for (String hostid : hostids) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("hostid", hostid);
            list.add(map);
        }
        param = list;
    } else {
        param = hostids;
    }

    JSONArray params = JSONArray.fromObject(param, defaultConfig);
    JSONObject result = (JSONObject) accessor.execute("host.delete", params);

    JSONArray resultHostids = result.getJSONArray("hostids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);
    return (List<String>) JSONArray.toCollection(resultHostids, config);
}
 
Example #28
Source File: ItemClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * アイテム情報を削除します。<br/>
 * itemidsパラメータを必ず指定する必要があります。<br/>
 * 存在しないitemidを指定した場合、例外をスローします。
 *
 * @param itemids itemids
 * @return 削除したアイテム情報のitemidのリスト
 */
public List<String> delete(List<String> itemids) {
    if (itemids == null || itemids.isEmpty()) {
        throw new IllegalArgumentException("itemid is required.");
    }

    JSONArray params = JSONArray.fromObject(itemids, defaultConfig);
    JSONObject result = (JSONObject) accessor.execute("item.delete", params);

    JSONArray itemIds = result.getJSONArray("itemids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);

    List<?> list = (List<?>) JSONArray.toCollection(itemIds, config);

    List<String> itemIdsList = new ArrayList<String>();
    for (Object object : list) {
        if (object instanceof String) {
            itemIdsList.add(String.class.cast(object));
        } else {
            itemIdsList.add(object.toString());
        }
    }

    return itemIdsList;
}
 
Example #29
Source File: JsonUtil.java    From JavaEE-SSH-Template with MIT License 5 votes vote down vote up
public static JSONObject jsonFilter(Object obj, String[] filterNames){
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setIgnoreDefaultExcludes(false);    
    jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);    //防止自包含
     
    if(filterNames != null){
        //这里是核心,过滤掉不想使用的属性
        jsonConfig .setExcludes(filterNames) ;
    }
    JSONObject jsonObj = JSONObject.fromObject(obj, jsonConfig);
    return jsonObj;
     
}
 
Example #30
Source File: UsergroupClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ユーザーグループ情報を取得します。<br/>
 * ユーザーグループ情報が存在しない場合、空のリストを返します。
 *
 * @param param {@link UsergroupGetParam}
 * @return 取得したユーザーグループ情報のリスト
 */
@SuppressWarnings("unchecked")
public List<Usergroup> get(UsergroupGetParam param) {
    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    JSONArray result = (JSONArray) accessor.execute("usergroup.get", params);

    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(Usergroup.class);
    return (List<Usergroup>) JSONArray.toCollection(result, config);
}