1. import com.alibaba.fastjson.JSONObject;
    2. import java.util.List;
    3. import java.util.stream.Collectors;
    4. public class ConverterUtil {
    5. public static <T> List<T> convertList(List<?> sourceList, Class<T> clazz) {
    6. return sourceList.stream().map(source -> (T) JSONObject.parseObject(JSONObject.toJSONString(source), clazz)).collect(Collectors.toList());
    7. }
    8. public static <T> T convert(Object source, Class<T> target) {
    9. return JSONObject.parseObject(JSONObject.toJSONString(source), target);
    10. }
    11. }