PropertyUtil extends PropertyUtils { public static void copyProperties(Object target, Object object) { copyProperties(target, object, null, null); } private  PropertyUtil(); static void safeSetCollectionProperty(Object bean, String name, Collection values); static void safeSetProperty(Object bean, String name, Object value); static Object safeGetProperty(Object bean, String name); static Class<?> safeGetPropertyType(Object bean, String name); static void copyProperties(Object target, Object object); static void copyProperties(Object target, Object object, ValueConverter converter); static void copyProperties(Object target, Object object, ValueConverter converter,
                                      Set<String> fieldsToUpdate); static List<String> findChangedFields(Object newInstance, Object oldInstance); static List<String> findChangedFields(Object newInstance, Object oldInstance, ValueConverter valueConverter);  }
@Test public void shouldCopyObjectValues() { TestClass fromDb = new TestClass(7, "fromDb", "accessible", 5L); TestClass transientObj = new TestClass(8, "transient", "changed", 6L); PropertyUtil.copyProperties(fromDb, transientObj); assertEquals(8, fromDb.publicInt); assertEquals("changed", fromDb.accessibleString); assertEquals("fromDb", fromDb.privateStr); assertEquals(Long.valueOf(5), fromDb.id); }
@Test public void shouldOnlyCopyFieldsPassedInSet() { TestClass fromDb = new TestClass(7, "fromDb", "accessible", 5L); TestClass transientObj = new TestClass(8, "transient", "changed", 6L); PropertyUtil.copyProperties(fromDb, transientObj, null, new HashSet<>(asList("publicInt"))); assertEquals(8, fromDb.publicInt); assertEquals("accessible", fromDb.accessibleString); assertEquals("fromDb", fromDb.privateStr); assertEquals(Long.valueOf(5), fromDb.id); }