JsonKit增加首字母大写序列号方法
This commit is contained in:
parent
2e239ab1cf
commit
d2fe9fc1c0
|
|
@ -1,22 +1,38 @@
|
||||||
package org.springblade.core.toolbox.kit;
|
package org.springblade.core.toolbox.kit;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.serializer.PascalNameFilter;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializeFilter;
|
||||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class JsonKit {
|
public class JsonKit {
|
||||||
|
|
||||||
public static String toJson(Object object) {
|
public static String toJson(Object object) {
|
||||||
return JSONObject.toJSONStringWithDateFormat(object, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat);
|
return JSONObject.toJSONStringWithDateFormat(object, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JSONObject parse(String text) {
|
public static String toJsonWithPascalName(Object object) {
|
||||||
return JSONObject.parseObject(text);
|
return JSON.toJSONString(object, SerializeConfig.globalInstance, new SerializeFilter[]{new PascalNameFilter()}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE, SerializerFeature.WriteDateUseDateFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T parse(String text, Class<T> clazz) {
|
public static JSONObject parse(String text) {
|
||||||
return JSONObject.parseObject(text, clazz);
|
return JSONObject.parseObject(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> T parse(String text, Class<T> clazz) {
|
||||||
|
return JSONObject.parseObject(text, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> List<T> parseArray(String text, Class<T> clazz) {
|
||||||
|
if (!(text.startsWith("[") && text.endsWith("]")))
|
||||||
|
text = "[" + text + "]";
|
||||||
|
return JSONObject.parseArray(text, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user