@Test public void shouldSetNullSetPropertyFromList() { TestClassWithCollections instance = new TestClassWithCollections(); Collection collection = new ArrayList(); collection.addAll(Arrays.asList("cow", "pig", "cat", "dog")); PropertyUtil.safeSetCollectionProperty(instance, "set", collection); assertNotNull(instance.getSet()); assertEquals(collection.size(), instance.getSet().size()); assertTrue(instance.getSet().containsAll(collection)); }
public static void safeSetCollectionProperty(Object bean, String name, Collection values) { try { Class collectionType = getPropertyType(bean, name); Collection property = instantiateCollection(collectionType); for (Object value : values) { property.add(value); } safeSetProperty(bean, name, property); } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LOGGER.error( "There was a problem with set values {} for property {} in bean: {}", values, name, bean, e); } }
PropertyUtil extends PropertyUtils { public static void safeSetCollectionProperty(Object bean, String name, Collection values) { try { Class collectionType = getPropertyType(bean, name); Collection property = instantiateCollection(collectionType); for (Object value : values) { property.add(value); } safeSetProperty(bean, name, property); } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LOGGER.error( "There was a problem with set values {} for property {} in bean: {}", values, name, bean, e); } } }
PropertyUtil extends PropertyUtils { public static void safeSetCollectionProperty(Object bean, String name, Collection values) { try { Class collectionType = getPropertyType(bean, name); Collection property = instantiateCollection(collectionType); for (Object value : values) { property.add(value); } safeSetProperty(bean, name, property); } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LOGGER.error( "There was a problem with set values {} for property {} in bean: {}", values, name, bean, e); } } private  PropertyUtil(); }
PropertyUtil extends PropertyUtils { public static void safeSetCollectionProperty(Object bean, String name, Collection values) { try { Class collectionType = getPropertyType(bean, name); Collection property = instantiateCollection(collectionType); for (Object value : values) { property.add(value); } safeSetProperty(bean, name, property); } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LOGGER.error( "There was a problem with set values {} for property {} in bean: {}", values, name, bean, e); } } 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); }
PropertyUtil extends PropertyUtils { public static void safeSetCollectionProperty(Object bean, String name, Collection values) { try { Class collectionType = getPropertyType(bean, name); Collection property = instantiateCollection(collectionType); for (Object value : values) { property.add(value); } safeSetProperty(bean, name, property); } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LOGGER.error( "There was a problem with set values {} for property {} in bean: {}", values, name, bean, e); } } 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);  }