
com.github.lontime.extjson.BeanCopy Maven / Gradle / Ivy
package com.github.lontime.extjson;
import java.util.Map;
import java.util.function.Function;
/**
* bean copy
* @author lontime
* @since 1.0
*/
public class BeanCopy {
/**
* copy.
* @param source source
* @param target target
* @param T
* @return target
*/
public static T copy(Object source, T target) {
final Map map = MapBeanHelper.beanToMap(source);
if (map == null || map.isEmpty()) {
return target;
}
return MapBeanHelper.mapToBean0(target, map);
}
/**
* copy.
* @param source source
* @param target target
* @param rename rename function
* @param T
* @return target
*/
public static T copy(Object source, T target, Function rename) {
final Map map = MapBeanHelper.beanToMap(source);
if (map == null || map.isEmpty()) {
return target;
}
return MapBeanHelper.mapToBean0(target, map, rename);
}
/**
* mixin.
* @param source source
* @param target target
* @param T
* @return target
*/
public static T mixin(T source, T target) {
final Map map = MapBeanHelper.beanToMap(source);
if (map == null || map.isEmpty()) {
return target;
}
return MapBeanHelper.mapToBean0(target, map, Function.identity());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy