Java——把list转为List<clazz>类型

把list类型转为List<clazz> 类型,其中,值为null时转为空字符串

public static <T> List<T> listFomart(List list, Class<T> clazz) {
    List<T> result = new ArrayList<>();
    list.forEach(item -> {
        result.add(JSON.parseObject(JSON.toJSONString(item, SerializerFeature.WriteNullStringAsEmpty), clazz,  Feature.InitStringFieldAsEmpty));
    });
    return result;
}

posted @ 2021-07-15 20:01  前方一片光明  阅读(302)  评论(0编辑  收藏  举报