Java Code Examples for com.alibaba.fastjson.JSONObject#replace()

The following examples show how to use com.alibaba.fastjson.JSONObject#replace() . These examples are extracted from open source projects. 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 Project: yue-library   File: UserService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 注册
 * 
 * @param paramJson
 * @return
 */
public Result<?> register(JSONObject paramJson) {
	// 1. 校验参数
	String[] mustContainKeys = {"cellphone", "password"};
	String[] canContainKeys = {"nickname", "email", "head_img", "sex", "birthday"};
	ParamUtils.paramValidate(paramJson, mustContainKeys, canContainKeys);

	// 2. 确认用户是否存在
	String cellphone = paramJson.getString("cellphone");
	validator.param(cellphone).cellphone("cellphone");
	if (userDAO.isUser(cellphone)) {
		return ResultInfo.devCustomTypePrompt(ResultPrompt.USER_EXIST);
	}
	
	// 3. 加密密码
	String password = paramJson.getString("password");
	password = SecureSingleton.getAES().encryptBase64(password);
	paramJson.replace("password", password);
	
	// 4. 插入数据
	paramJson.put("role", RoleEnum.b2c_买家.name());
	return ResultInfo.success(userDAO.insert(paramJson));
}
 
Example 2
Source Project: yue-library   File: ParamUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 参数美化-Object强类型转换
 * @param paramJson				需要向强类型转换的参数
 * @param paramFormatIPOList	多个参数美化IPO
 */
public static void paramFormatObject(JSONObject paramJson, List<ParamFormatIPO> paramFormatIPOList) {
	for (ParamFormatIPO paramFormatIPO : paramFormatIPOList) {
		String key = paramFormatIPO.getKey();
		Class<?> clazz = paramFormatIPO.getClazz();
		paramJson.replace(key, paramJson.getObject(key, clazz));
	}
}
 
Example 3
Source Project: yue-library   File: ListUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@linkplain List}-{@linkplain JSONObject}集合——去重、统计、排序与元素选择性保留
 * <p>根据参数distinctKey(JSONObject的key),计算元素重复次数。并为每个JSONObject添加一个<b>frequency</b>(频率元素),value的值是从整数1开始计数。
 * <p>示例:<code>json.put("frequency", frequency)</code>
 * <p><b>根据frequency(重复频率)排序</b>

 * @param list 需要处理的集合
 * @param distinctKey 去重的依据(JSONObject的key)
 * @param sortEnum 排序方式
 * @param keepKey 需要保留的重复元素(此参数必须为可判断的Number类型:根据maxOrMinEnum选择保留最大值 <i>或</i> 最小值)<b><i>如:</i></b>根据id去重,保留age为最大或最小的JSONObject
 * @param maxOrMinEnum 保留的值:最大值 <i>或</i> 最小值
 * @return 处理后的List集合
 */
public static List<JSONObject> distinctCountSortSelectKeep(List<JSONObject> list, String distinctKey, SortEnum sortEnum, String keepKey, MaxOrMinEnum maxOrMinEnum) {
	for (int i = 0; i < list.size(); i++) {
		int frequency = 1;
		JSONObject jsoni = list.get(i);
		for (int j = list.size() - 1; j > i; j--) {
			JSONObject jsonj = list.get(j);
			if (jsoni.get(distinctKey).equals(jsonj.get(distinctKey))) {
				// i > j
				if (CompareUtil.compare(jsoni.get(keepKey), jsonj.get(keepKey), false) > 0) {
					if (maxOrMinEnum == MaxOrMinEnum.最小值) {
						jsoni.replace(keepKey, jsonj.get(keepKey));
					}
					list.remove(j);
					frequency++;
				} else {
					if (maxOrMinEnum == MaxOrMinEnum.最大值) {
						jsoni.replace(keepKey, jsonj.get(keepKey));
					}
					list.remove(j);
					frequency++;
				}
			}
		}
		jsoni.put("frequency", frequency);
	}
	
	return sort(list, "frequency", sortEnum);
}
 
Example 4
Source Project: yue-library   File: ParamUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 参数美化-Boolean强类型转换
 * @param paramJson	需要向强类型转换的参数
 * @param keys		可多个boolean值的key
 */
public static void paramFormatBoolean(JSONObject paramJson, String... keys) {
	for (String key : keys) {
		paramJson.replace(key, paramJson.getBoolean(key));
	}
}
 
Example 5
Source Project: yue-library   File: ParamUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 参数美化-BigDecimal强类型转换
 * @param paramJson	需要向强类型转换的参数
 * @param keys		可多个BigDecimal值的key
 */
public static void paramFormatBigDecimal(JSONObject paramJson, String... keys) {
	for (String key : keys) {
		paramJson.replace(key, paramJson.getBigDecimal(key));
	}
}
 
Example 6
Source Project: yue-library   File: ParamUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 参数美化-JSONObject强类型转换
 * @param paramJson	需要向强类型转换的参数
 * @param keys		可多个JSONObject值的key
 */
public static void paramFormatJSONObject(JSONObject paramJson, String... keys) {
	for (String key : keys) {
		paramJson.replace(key, paramJson.getJSONObject(key));
	}
}
 
Example 7
Source Project: yue-library   File: ParamUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 参数美化-JSONArray强类型转换
 * @param paramJson	需要向强类型转换的参数
 * @param keys		可多个JSONArray值的key
 */
public static void paramFormatJSONArray(JSONObject paramJson, String... keys) {
	for (String key : keys) {
		paramJson.replace(key, paramJson.getJSONArray(key));
	}
}