@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; }
/** * 返回服务端处理结果 * @param obj 服务端输出对象 * @return 输出处理结果给前段JSON格式数据 * @author YANGHONGXIA * @since 2015-01-06 */ public String responseResult(Object obj){ JSONObject jsonObj = null; if(obj != null){ logger.info("后端返回对象:{}", obj); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); jsonObj = JSONObject.fromObject(obj, jsonConfig); logger.info("后端返回数据:" + jsonObj); if(HttpConstants.SERVICE_RESPONSE_SUCCESS_CODE.equals(jsonObj.getString(HttpConstants.SERVICE_RESPONSE_RESULT_FLAG))){ jsonObj.element(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, false); jsonObj.element(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, ""); }else{ jsonObj.element(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, true); String errMsg = jsonObj.getString(HttpConstants.SERVICE_RESPONSE_RESULT_MSG); jsonObj.element(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, errMsg==null?HttpConstants.SERVICE_RESPONSE_NULL:errMsg); } } logger.info("输出结果:{}", jsonObj.toString()); return jsonObj.toString(); }
/** * 把数据对象转换成json字符串 DTO对象形如:{"id" : idValue, "name" : nameValue, ...} * 数组对象形如:[{}, {}, {}, ...] map对象形如:{key1 : {"id" : idValue, "name" : * nameValue, ...}, key2 : {}, ...} * * @param object * @return */ public static String getJSONString(Object object) throws Exception { String jsonString = null; // 日期值处理器 JsonConfig jsonConfig = new JsonConfig(); if (object != null) { if (object instanceof Collection || object instanceof Object[]) { jsonString = JSONArray.fromObject(object, jsonConfig) .toString(); } else { jsonString = JSONObject.fromObject(object, jsonConfig) .toString(); } } return jsonString == null ? "{}" : jsonString; }
@Transactional public String getJsonList(PageBean pageBean, Map<String, Object> map, String order, HttpServletRequest request, Map<String, Object> otherParams, String[] excludes) { if (order == null && request != null) { order = " "; order += StringUtils.isEmpty(request.getParameter("sortname")) ? " id" : " " + request.getParameter("sortname"); order += StringUtils.isEmpty(request.getParameter("sortorder")) ? " desc" : " " + request.getParameter("sortorder"); } List<T> list = new ArrayList<T>(); list = getList(pageBean, map, order); HashMap<String, Object> tempMap = new HashMap<String, Object>(); tempMap.put(Const.Page, pageBean); tempMap.put(Const.Rows, list); tempMap.put("Total", pageBean.getDataSize()); 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()); } } JsonConfig config = new JsonConfig(); if (excludes == null) { excludes = new String[] {}; // 待添�? } config.setExcludes(excludes);// 出去dept属�? JSONObject json = JSONObject.fromObject(tempMap, config); return json.toString(); }
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()); }
/** * 把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", "[]")); }
/** * 得到指定图书编号的图书信息 * ajax请求该方法 * 返回该图书信息的json对象 * @return */ public String getBook(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Book book = new Book(); book.setBookId(bookId); Book newBook = bookService.getBookById(book);//得到图书 JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Authorization||name.equals("authorization")){ return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newBook,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
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; }
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; }
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; }
/** * 根据借阅id查询该借阅信息 * @return */ public String getBorrowInfoById(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); BorrowInfo info = new BorrowInfo(); info.setBorrowId(borrowId); BorrowInfo newInfo = borrowService.getBorrowInfoById(info); 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(newInfo,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
/** * 返回成功 * @param obj 输出对象 * @return 输出成功的JSON格式数据 */ public String responseSuccess(Object obj){ JSONObject jsonObj = null; if(obj != null){ logger.info("后端返回对象:{}", obj); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); jsonObj = JSONObject.fromObject(obj, jsonConfig); logger.info("后端返回数据:" + jsonObj); jsonObj.element(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, false); jsonObj.element(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, ""); } logger.info("输出结果:{}", jsonObj.toString()); return jsonObj.toString(); }
/** * 返回成功 * @param obj 输出对象 * @return 输出成功的JSON格式数据 */ public String responseMemberSuccess(Object obj){ JSONObject jsonObj = null; if(obj != null){ logger.info("后端返回对象:{}", obj); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); jsonObj = JSONObject.fromObject(obj, jsonConfig); logger.info("后端返回数据:" + jsonObj); } logger.info("输出结果:{}", jsonObj.toString()); return jsonObj.toString(); }
/** * 返回成功 * @param obj 输出对象 * @return 输出成功的JSON格式数据 */ public String responseSuccess(Object obj, String msg){ JSONObject jsonObj = null; if(obj != null){ logger.info("后端返回对象:{}", obj); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); jsonObj = JSONObject.fromObject(obj, jsonConfig); logger.info("后端返回数据:" + jsonObj); jsonObj.element(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, false); jsonObj.element(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, msg); } logger.info("输出结果:{}", jsonObj.toString()); return jsonObj.toString(); }
public String attrs() throws Exception { HttpServletRequest request=Struts2Utils.getRequest(); HttpServletResponse response=Struts2Utils.getResponse(); try{ SurveyDirectory survey=surveyDirectoryManager.getSurvey(id); JsonConfig cfg = new JsonConfig(); cfg.setExcludes(new String[]{"handler","hibernateLazyInitializer"}); JSONObject jsonObject=JSONObject.fromObject(survey,cfg); response.getWriter().write(jsonObject.toString()); }catch(Exception e){ e.printStackTrace(); } return null; }
public ActionForward getDemographic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { String demographicNo = request.getParameter("demographicNo"); if(!securityInfoManager.hasPrivilege(LoggedInInfo.getLoggedInInfoFromSession(request), "_demographic", "r", null)) { throw new SecurityException("missing required security object (_demographic)"); } Demographic demographic = demographicDao.getDemographic(demographicNo); JsonConfig config = new JsonConfig(); config.registerJsonBeanProcessor(java.sql.Date.class, new JsDateJsonBeanProcessor()); JSONObject json = JSONObject.fromObject(demographic,config); response.getOutputStream().write(json.toString().getBytes()); return null; }
/** * * @param jsonStr * 需转换的标准的json字符串 * @param clz * 转换对象 * @param classMap * 转换对象中包含复杂对象,key对应jsonStr中key,value对应需转换为的复杂对象 * @return */ public static <T> T jsonString2Bean(String jsonStr, Class<T> clz, Map<String, Class<?>> classMap) { JSONObject json_obj = null; try { json_obj = JSONObject.fromObject(jsonStr); } catch (JSONException e) { e.printStackTrace(); } if (json_obj == null) return null; JsonConfig config = new JsonConfig(); config.setRootClass(clz); config.setClassMap(classMap); config.setHandleJettisonEmptyElement(true); return (T) JSONObject.toBean(json_obj, config); }
public static JSONArray jsonListFilter(List objList, String[] filterNames){ JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setIgnoreDefaultExcludes(false); jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); //防止自包含 if(filterNames != null){ //这里是核心,过滤掉不想使用的属性 jsonConfig .setExcludes(filterNames) ; } JSONArray jsonArray = JSONArray.fromObject(objList, jsonConfig); return jsonArray; }
@Override public Object doRequest(Map<String, Object> params) { LogUtil.printInfoLog(params); String mid = (String) params.get("mid"); Integer begin_date = (Integer) params.get("begin_date"); Integer end_date = (Integer) params.get("end_date"); MMSNotice mmsNotice = new MMSNotice(); mmsNotice.setMid(mid); mmsNotice.setBeginDate(begin_date); mmsNotice.setEndDate(end_date); List<MMSNotice> list = new SystemDao().getMessage(mmsNotice); JSONObject pageObj = new JSONObject(); JSONArray jsonArr = new JSONArray(); JsonConfig jsonConfig = new JsonConfig(); for (MMSNotice notice : list) { jsonArr.add(JSONObject.fromObject(notice),jsonConfig); } pageObj.put("mmsNotice", jsonArr); return pageObj; }
public Object doRequest(Map<String, Object> params) { String mid = (String) params.get("mid"); Integer pageNo = (Integer) params.get("page_no"); if(Ryt.empty(mid)) return "商户号不能为空"; if(pageNo <= 0){ return "参数错误: pageNo = " + pageNo; } CurrentPage<OperInfo> page = new MerchantService().getOpers4Object(mid, null, pageNo); JSONObject pageObj = new JSONObject(); JSONArray jsonArr = new JSONArray(); JsonConfig jsonConfig = new JsonConfig(); List<OperInfo> list = page.getPageItems(); for (OperInfo operInfo : list) { jsonArr.add(JSONObject.fromObject(operInfo),jsonConfig); } pageObj.put("operInfo", jsonArr); pageObj.put("pageNo", pageNo); pageObj.put("pageSize", page.getPageSize()); pageObj.put("totalRecord", page.getPageTotle()); pageObj.put("pagesAvailable", page.getPagesAvailable()); return pageObj; }
@Override public String toString() { JsonConfig config = new JsonConfig(); DefaultValueProcessor dvp = new DefaultValueProcessor(){ @Override public Object getDefaultValue(Class type) { return ""; } }; config.registerDefaultValueProcessor(Integer.class, dvp); config.registerDefaultValueProcessor(Short.class, dvp); config.registerDefaultValueProcessor(Long.class, dvp); config.registerDefaultValueProcessor(String.class, dvp); config.registerDefaultValueProcessor(Byte.class, dvp); config.registerDefaultValueProcessor(Character.class, dvp); config.registerDefaultValueProcessor(Float.class, dvp); config.registerDefaultValueProcessor(Double.class, dvp); return JSONObject.fromObject(this,config).toString(); }
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; }
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; }
/** * JSON 时间解析器具 */ public static JsonConfig configJson(String datePattern) { JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setExcludes(new String[] { "" }); jsonConfig.setIgnoreDefaultExcludes(false); jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor(datePattern)); return jsonConfig; }
/** * 除去不想生成的字段(特别适合去掉级联的对象)+时间转换 * * @param excludes * 除去不想生成的字段 * @param datePattern * @return */ public static JsonConfig configJson(String[] excludes, String datePattern) { JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setExcludes(excludes); jsonConfig.setIgnoreDefaultExcludes(true); jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor(datePattern)); return jsonConfig; }
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; }
/** * ユーザグループ情報を作成します。<br/> * nameパラメータを必ず指定する必要があります。<br/> * 既に存在するユーザグループのnameを指定した場合、例外をスローします。 * * @param param {@link UsergroupCreateParam} * @return 作成されたユーザグループ情報のusrgrpidのリスト */ @SuppressWarnings("unchecked") public List<String> create(UsergroupCreateParam param) { if (param.getName() == null || param.getName().length() == 0) { throw new IllegalArgumentException("name 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.create", 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); }
/** * ユーザグループ情報とユーザ情報、権限情報を紐付けます。 * 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; }
/** * ユーザグループ情報を更新します。 * 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); }
/** * トリガー情報を取得します。<br/> * トリガー情報が存在しない場合、空のリストを返します。 * * @param param {@link TriggerGetParam} * @return 取得したトリガー情報のリスト */ @SuppressWarnings("unchecked") public List<Trigger> get(TriggerGetParam param) { JSONObject params = JSONObject.fromObject(param, defaultConfig); JSONArray result = (JSONArray) accessor.execute("trigger.get", params); JsonConfig config = defaultConfig.copy(); config.setCollectionType(List.class); config.setRootClass(Trigger.class); config.setJavaPropertyFilter(new PropertyFilter() { @Override public boolean apply(Object source, String name, Object value) { if ("hosts".equals(name)) { return true; } return false; } }); return (List<Trigger>) JSONArray.toCollection(result, config); }
/** * ユーザ情報を取得します。<br/> * ユーザ情報が存在しない場合、空のリストを返します。 * * @param param {@link UserGetParam} * @return 取得したユーザ情報のリスト */ @SuppressWarnings("unchecked") public List<User> get(UserGetParam param) { JSONObject params = JSONObject.fromObject(param, defaultConfig); if (accessor.checkVersion("2.0") < 0) { if (params.containsKey("selectUsrgrps")) { params.put("select_usrgrps", params.remove("selectUsrgrps")); } } JSONArray result = (JSONArray) accessor.execute("user.get", params); JsonConfig config = defaultConfig.copy(); config.setCollectionType(List.class); config.setRootClass(User.class); config.getClassMap().put("usrgrps", Usergroup.class); return (List<User>) JSONArray.toCollection(result, config); }
/** * ユーザ情報を作成します。<br/> * aliasパラメータを必ず指定する必要があります。<br/> * 既に存在するユーザのaliasを指定した場合、例外をスローします。 * * @param param {@link UserCreateParam} * @return 作成されたユーザ情報のuseridのリスト */ @SuppressWarnings("unchecked") public List<String> create(UserCreateParam param) { if (param.getAlias() == null || param.getAlias().length() == 0) { throw new IllegalArgumentException("alias is required."); } if (accessor.checkVersion("2.0") >= 0) { if (param.getPasswd() == null || param.getPasswd().length() == 0) { throw new IllegalArgumentException("passwd is required."); } if (param.getUsrgrps() == null || param.getUsrgrps().isEmpty()) { throw new IllegalArgumentException("usrgrps is required."); } } JSONObject params = JSONObject.fromObject(param, defaultConfig); JSONObject result = (JSONObject) accessor.execute("user.create", params); JSONArray userids = result.getJSONArray("userids"); JsonConfig config = defaultConfig.copy(); config.setCollectionType(List.class); config.setRootClass(String.class); return (List<String>) JSONArray.toCollection(userids, config); }
/** * アイテム情報を取得します。<br/> * アイテム情報が存在しない場合、空のリストを返します。 * * @param param {@link ItemGetParam} * @return 取得したアイテム情報のリスト */ @SuppressWarnings("unchecked") public List<Item> get(ItemGetParam param) { JSONObject params = JSONObject.fromObject(param, defaultConfig); JSONArray result = (JSONArray) accessor.execute("item.get", params); JsonConfig config = defaultConfig.copy(); config.setCollectionType(List.class); config.setRootClass(Item.class); config.setJavaPropertyFilter(new PropertyFilter() { @Override public boolean apply(Object source, String name, Object value) { if ("hosts".equals(name)) { return true; } return false; } }); return (List<Item>) JSONArray.toCollection(result, config); }
/** * アイテム情報を更新します。<br/> * itemidパラメータを必ず指定する必要があります。 * * @param param {@link ItemUpdateParam} * @return 更新したアイテム情報のitemidのリスト */ @SuppressWarnings("unchecked") public List<String> update(ItemUpdateParam param) { if (param.getItemid() == null) { throw new IllegalArgumentException("itemid is required."); } JSONObject params = JSONObject.fromObject(param, defaultConfig); JSONObject result = (JSONObject) accessor.execute("item.update", params); JSONArray itemids = result.getJSONArray("itemids"); JsonConfig config = defaultConfig.copy(); config.setCollectionType(List.class); config.setRootClass(String.class); return (List<String>) JSONArray.toCollection(itemids, config); }