DataUtil { public static List<String> getStringList(Object object) { if (object == null) { return null; } String[] result; if (object instanceof List) { List<String> orig = (List<String>)object; List<String> list = new ArrayList<>(orig.size()); for(int i = 0; i < orig.size(); i ++) { list.add(String.valueOf(orig.get(i))); } return list; } else if (object instanceof String[]) { result = (String[])object; List<String> list = new ArrayList<>(result.length); Collections.addAll(list, result); return list; } else if (object instanceof String) { String str = (String)object; str = str.trim(); result = StringUtils.split(str, ','); List<String> list = new ArrayList<>(result.length); Collections.addAll(list, result); return list; } else if (object instanceof Object[]) { Object[] array = (Object[])object; List<String> list = new ArrayList<>(array.length); for (Object anArray : array) { list.add(getString(anArray, null)); } return list; } else if (object.getClass().isArray()) { int len = Array.getLength(object); List<String> list = new ArrayList<>(len); for (int i = 0; i < len; i++) { list.add(getString(Array.get(object, i), null)); } return list; } else if (object instanceof Number || object instanceof Boolean || object instanceof Character) { return Collections.singletonList(object.toString()); } else { return null; } }  static boolean getBoolean(Object value, boolean defValue); static Boolean doGetBoolean(Object value, Boolean defValue); static boolean toBoolean(String value, boolean defValue); static Boolean convertToBoolean(String value, Boolean defValue); static boolean toBoolean(String value); static int getInt(Object value, int defValue); static long getLong(Object value, long defValue); static double getDouble(Object value, double defValue); static String getString(Object value, String defValue); static String[] getStringArray(Object object, String[] defValue); static int[] getIntArray(Object object, int[] defValue); static List<String> getStringList(Object object);  }
@Test public void getStringList() throws Exception { assertNull(DataUtil.getStringList(null)); assertNull(DataUtil.getStringList(new Object())); List<String> list = new ArrayList<>(); list.add("true"); assertArrayEquals(DataUtil.getStringList(list).toArray(), new String[] {"true"}); assertArrayEquals(DataUtil.getStringList(Boolean.TRUE).toArray(), new String[] {"true"}); assertArrayEquals(DataUtil.getStringList(Boolean.FALSE).toArray(), new String[] {"false"}); assertArrayEquals(DataUtil.getStringList("True").toArray(), new String[] { "True" }); assertArrayEquals(DataUtil.getStringList("99").toArray(), new String[] {"99"}); assertArrayEquals(DataUtil.getStringList(" 88 ").toArray(), new String[] {"88"}); assertArrayEquals(DataUtil.getStringList(new String[] {"DDDDD"}).toArray(), new String[] {"DDDDD"}); assertArrayEquals(DataUtil.getStringList(888L).toArray(), new String[] {"888"}); assertArrayEquals(DataUtil.getStringList('a').toArray(), new String[] {"a"}); assertArrayEquals(DataUtil.getStringList(new Object[] {'a', 123}).toArray(), new String[] {"a", "123"}); assertArrayEquals(DataUtil.getStringList(new int[] {345, 123}).toArray(), new String[] {"345", "123"}); }