import com.alibaba.fastjson.JSON;
import java.util.List;
import org.springframework.util.CollectionUtils;
/** @deprecated */
@Deprecated
public class ObjectConversion {
public ObjectConversion() {
}
public static <T> List<T> copy(List<?> list, Class<T> clazz) {
if (CollectionUtils.isEmpty(list)) {
return null;
} else {
String oldOb = JSON.toJSONString(list);
return JSON.parseArray(oldOb, clazz);
}
}
public static <T> T copy(Object ob, Class<T> clazz) {
if (null == ob) {
return null;
} else {
String oldOb = JSON.toJSONString(ob);
return JSON.parseObject(oldOb, clazz);
}
}
}
//使用demo
List<Entity> copy = ObjectConversion.copy(list, Entity.class);
//最求效率的话,可以使用mapstruct。官方文档地址:https://mapstruct.org/