@Test public void copyByAnnotation() { AnnoBean bean = new AnnoBean(); bean.setCompany(new StringBuilder("comp")); bean.setTest1(11); bean.setTest2(22); bean.setTest3("33"); bean.setTest4("44"); AnnoBean acopied = new AnnoBean(); BeanCopy.copyByAnnotation(bean, acopied); Assert.assertNull(null, acopied.getTest3()); Assert.assertEquals("44", acopied.getTest4()); logger.info(acopied); }
public static void copyByAnnotation(Object src, Object dest) { if (ObjectUtil.isAnyNull(src, dest)) { return; } Class<?> srcClazz = src.getClass(); Class<?> destClazz = dest.getClass(); Field[] destFields = fieldCache.getInstanceFields(dest.getClass()); for (Field field : destFields) { if (ReflectionUtil.isFinal(field) || ReflectionUtil.hasAnnotation(field, IgnoreField.class)) { continue; } Field srcField = fieldCache.getField(srcClazz, CopyField.class, field.getName()); if (srcField != null && supportFor(destClazz, srcField.getAnnotation(CopyField.class))) { Object value = ReflectionUtil.readField(srcField, src); ReflectionUtil.writeField(field, dest, value); } } }
BeanCopy { public static void copyByAnnotation(Object src, Object dest) { if (ObjectUtil.isAnyNull(src, dest)) { return; } Class<?> srcClazz = src.getClass(); Class<?> destClazz = dest.getClass(); Field[] destFields = fieldCache.getInstanceFields(dest.getClass()); for (Field field : destFields) { if (ReflectionUtil.isFinal(field) || ReflectionUtil.hasAnnotation(field, IgnoreField.class)) { continue; } Field srcField = fieldCache.getField(srcClazz, CopyField.class, field.getName()); if (srcField != null && supportFor(destClazz, srcField.getAnnotation(CopyField.class))) { Object value = ReflectionUtil.readField(srcField, src); ReflectionUtil.writeField(field, dest, value); } } } }
BeanCopy { public static void copyByAnnotation(Object src, Object dest) { if (ObjectUtil.isAnyNull(src, dest)) { return; } Class<?> srcClazz = src.getClass(); Class<?> destClazz = dest.getClass(); Field[] destFields = fieldCache.getInstanceFields(dest.getClass()); for (Field field : destFields) { if (ReflectionUtil.isFinal(field) || ReflectionUtil.hasAnnotation(field, IgnoreField.class)) { continue; } Field srcField = fieldCache.getField(srcClazz, CopyField.class, field.getName()); if (srcField != null && supportFor(destClazz, srcField.getAnnotation(CopyField.class))) { Object value = ReflectionUtil.readField(srcField, src); ReflectionUtil.writeField(field, dest, value); } } }  }
BeanCopy { public static void copyByAnnotation(Object src, Object dest) { if (ObjectUtil.isAnyNull(src, dest)) { return; } Class<?> srcClazz = src.getClass(); Class<?> destClazz = dest.getClass(); Field[] destFields = fieldCache.getInstanceFields(dest.getClass()); for (Field field : destFields) { if (ReflectionUtil.isFinal(field) || ReflectionUtil.hasAnnotation(field, IgnoreField.class)) { continue; } Field srcField = fieldCache.getField(srcClazz, CopyField.class, field.getName()); if (srcField != null && supportFor(destClazz, srcField.getAnnotation(CopyField.class))) { Object value = ReflectionUtil.readField(srcField, src); ReflectionUtil.writeField(field, dest, value); } } }  static void copy(Object src, Object dest, boolean useAnnotation); static void copyProperties(Object src, Object dest); static void copyByAnnotation(Object src, Object dest); static void copyByMethod(Object src, Object dest); }
BeanCopy { public static void copyByAnnotation(Object src, Object dest) { if (ObjectUtil.isAnyNull(src, dest)) { return; } Class<?> srcClazz = src.getClass(); Class<?> destClazz = dest.getClass(); Field[] destFields = fieldCache.getInstanceFields(dest.getClass()); for (Field field : destFields) { if (ReflectionUtil.isFinal(field) || ReflectionUtil.hasAnnotation(field, IgnoreField.class)) { continue; } Field srcField = fieldCache.getField(srcClazz, CopyField.class, field.getName()); if (srcField != null && supportFor(destClazz, srcField.getAnnotation(CopyField.class))) { Object value = ReflectionUtil.readField(srcField, src); ReflectionUtil.writeField(field, dest, value); } } }  static void copy(Object src, Object dest, boolean useAnnotation); static void copyProperties(Object src, Object dest); static void copyByAnnotation(Object src, Object dest); static void copyByMethod(Object src, Object dest);  }