如何封装一个json工具类?
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
public class JSONUtil {
public JSONUtil() {
}
public static <T> T fromObject(String json, Class<T> clazz) {
return JSON.parseObject(json, clazz);
}
public static String toJson(Object obj) {
return JSON.toJSONString(obj);
}
public static <T> List<T> fromObjectByArray(String json, Class<T> clazz) {
return JSONObject.parseArray(json, clazz);
}
}