|
@@ -1,17 +1,22 @@
|
|
|
package api.common.util;
|
|
|
|
|
|
+import api.common.pojo.po.scene.SceneGeneralTemplatePO;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.JavaType;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.node.TextNode;
|
|
|
import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
|
+import org.apache.tomcat.jni.User;
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
public class JsonUtil {
|
|
|
|
|
@@ -57,10 +62,10 @@ public class JsonUtil {
|
|
|
|
|
|
public static <T> List<T> jsonToList(String json, Class<T> tClass) throws JsonProcessingException {
|
|
|
JavaType javaType = TypeFactory.defaultInstance().constructParametricType(List.class, tClass);
|
|
|
- if(ObjectUtil.isNull(json)){
|
|
|
+ if (ObjectUtil.isNull(json)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
- List<T> list = new ObjectMapper().readValue(json,javaType);
|
|
|
+ List<T> list = new ObjectMapper().readValue(json, javaType);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
@@ -81,4 +86,45 @@ public class JsonUtil {
|
|
|
}
|
|
|
return new TextNode("");
|
|
|
}
|
|
|
+
|
|
|
+//泛化用的,把带下划线的json转换为驼峰jsom
|
|
|
+ public static String stringToJson(String ss) throws JsonProcessingException {
|
|
|
+ Map maps = jsonToMap(ss);
|
|
|
+ Map map = new HashMap();
|
|
|
+ for (Object obj : maps.keySet()) {
|
|
|
+ String value = underlineToHump(obj.toString());
|
|
|
+ map.put(value, maps.get(obj));
|
|
|
+ }
|
|
|
+ return beanToJson(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Pattern UNDERLINE_PATTERN = Pattern.compile("_([a-z])");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据传入的带下划线的字符串转化为驼峰格式
|
|
|
+ *
|
|
|
+ * @param str
|
|
|
+ * @return
|
|
|
+ * @author mrf
|
|
|
+ */
|
|
|
+
|
|
|
+ public static String underlineToHump(String str) {
|
|
|
+ //正则匹配下划线及后一个字符,删除下划线并将匹配的字符转成大写
|
|
|
+ Matcher matcher = UNDERLINE_PATTERN.matcher(str);
|
|
|
+ StringBuffer sb = new StringBuffer(str);
|
|
|
+ if (matcher.find()) {
|
|
|
+ sb = new StringBuffer();
|
|
|
+ //将当前匹配的子串替换成指定字符串,并且将替换后的子串及之前到上次匹配的子串之后的字符串添加到StringBuffer对象中
|
|
|
+ //正则之前的字符和被替换的字符
|
|
|
+ matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
|
|
|
+ //把之后的字符串也添加到StringBuffer对象中
|
|
|
+ matcher.appendTail(sb);
|
|
|
+ } else {
|
|
|
+ //去除除字母之外的前面带的下划线
|
|
|
+ return sb.toString().replaceAll("_", "");
|
|
|
+ }
|
|
|
+ return underlineToHump(sb.toString());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|