All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codingapi.springboot.framework.convert.BeanConvertor Maven / Gradle / Ivy

There is a newer version: 3.3.12
Show newest version
package com.codingapi.springboot.framework.convert;

import org.springframework.beans.BeanUtils;

import java.lang.reflect.InvocationTargetException;

public class BeanConvertor {

    public static  T convert(S source, Class clazz) {
        if (source == null) {
            return null;
        }
        T target = null;
        try {
            target = clazz.getDeclaredConstructor().newInstance();
        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
                 InvocationTargetException e) {
            return null;
        }
        BeanUtils.copyProperties(source, target);
        return target;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy