import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import java.util.List;
public class JsonUtil {
private static final SerializerFeature[] DEFAULT_S_FEATURES;
public JsonUtil() {
}
public static String toJsonString(Object object) {
return JSON.toJSONString(object, DEFAULT_S_FEATURES);
}
public static String toPrettyJson(Object object) {
return JSON.toJSONString(object, new SerializerFeature[]{SerializerFeature.WriteDateUseDateFormat, SerializerFeature.SortField, SerializerFeature.PrettyFormat});
}
public static String toJsonString(Object object, SerializerFeature... serializerFeature) {
return JSON.toJSONString(object, serializerFeature);
}
public static <T> T parseObject(String jsonStr, Class<T> clazz) {
return JSON.parseObject(jsonStr, clazz);
}
public static JSONObject parseJsonObject(String jsonStr) {
return JSON.parseObject(jsonStr);
}
public static JSONArray parseJsonArray(String jsonStr) {
return JSON.parseArray(jsonStr);
}
public static <T> List<T> parseArray(String jsonStr, Class<T> clazz) {
return JSON.parseArray(jsonStr, clazz);
}
static {
DEFAULT_S_FEATURES = new SerializerFeature[]{SerializerFeature.WriteDateUseDateFormat, SerializerFeature.SortField};
}
}
乡振开源JSON解析工具封装
于 2024-01-06 15:35:26 首次发布