PropertiesUtil { public static Object toObject(Object propValue) { if (propValue == null) { return null; } else if (propValue.getClass().isArray()) { Object[] prop = (Object[]) propValue; return prop.length > 0 ? prop[0] : null; } else if (propValue instanceof Collection<?>) { Collection<?> prop = (Collection<?>) propValue; return prop.isEmpty() ? null : prop.iterator().next(); } else { return propValue; } } private  PropertiesUtil(); static boolean toBoolean(Object propValue, boolean defaultValue); static String toString(Object propValue, String defaultValue); static long toLong(Object propValue, long defaultValue); static int toInteger(Object propValue, int defaultValue); static double toDouble(Object propValue, double defaultValue); static Object toObject(Object propValue); static String[] toStringArray(Object propValue); static String[] toStringArray(Object propValue, String[] defaultArray); @SuppressWarnings("unchecked") static void populate(Object instance, Map<String,?> config, boolean validate);  }
@Test public void testToObject() { assertEquals("hallo", PropertiesUtil.toObject("hallo")); assertEquals("1", PropertiesUtil.toObject(new String[]{"1", "2"})); assertEquals(null, PropertiesUtil.toObject(null)); assertEquals(null, PropertiesUtil.toObject(new String[]{})); final List<String> l = new ArrayList<String>(); assertEquals(null, PropertiesUtil.toObject(l)); l.add("1"); assertEquals("1", PropertiesUtil.toObject(l)); l.add("2"); assertEquals("1", PropertiesUtil.toObject(l)); final Map<String, Object> m = new HashMap<String, Object>(); assertEquals(m, PropertiesUtil.toObject(m)); }