@Test void toStringIterable() { Iterable<String> iterable = () -> asList("str1", "str2").iterator(); assertEquals("str1,str2", DataConverter.toString(iterable)); }
@Nullable @CheckForNull public static String toString(@Nullable @CheckForNull Object source) { if (source == null) { return null; } if (source instanceof String) { return (String) source; } if (source instanceof Iterable<?>) { StringBuilder sb = new StringBuilder(); for (Object obj : (Iterable<?>) source) { if (sb.length() > 0) sb.append(","); sb.append(toString(obj)); } return sb.toString(); } return convert(source, String.class); }
DataConverter { @Nullable @CheckForNull public static String toString(@Nullable @CheckForNull Object source) { if (source == null) { return null; } if (source instanceof String) { return (String) source; } if (source instanceof Iterable<?>) { StringBuilder sb = new StringBuilder(); for (Object obj : (Iterable<?>) source) { if (sb.length() > 0) sb.append(","); sb.append(toString(obj)); } return sb.toString(); } return convert(source, String.class); } }
DataConverter { @Nullable @CheckForNull public static String toString(@Nullable @CheckForNull Object source) { if (source == null) { return null; } if (source instanceof String) { return (String) source; } if (source instanceof Iterable<?>) { StringBuilder sb = new StringBuilder(); for (Object obj : (Iterable<?>) source) { if (sb.length() > 0) sb.append(","); sb.append(toString(obj)); } return sb.toString(); } return convert(source, String.class); } private  DataConverter(); }
DataConverter { @Nullable @CheckForNull public static String toString(@Nullable @CheckForNull Object source) { if (source == null) { return null; } if (source instanceof String) { return (String) source; } if (source instanceof Iterable<?>) { StringBuilder sb = new StringBuilder(); for (Object obj : (Iterable<?>) source) { if (sb.length() > 0) sb.append(","); sb.append(toString(obj)); } return sb.toString(); } return convert(source, String.class); } private  DataConverter(); static Object convert(Object source, Attribute attr); @Nullable @CheckForNull static String toString(@Nullable @CheckForNull Object source); @Nullable @CheckForNull static Integer toInt(@Nullable @CheckForNull Object source); @Nullable @CheckForNull static Long toLong(@Nullable @CheckForNull Object source); @SuppressWarnings("java:S2447") // null is a valid return value @Nullable @CheckForNull static Boolean toBoolean(@Nullable @CheckForNull Object source); @Nullable @CheckForNull static Double toDouble(@Nullable @CheckForNull Object source); @Nullable @CheckForNull static LocalDate toLocalDate(@Nullable @CheckForNull Object source); @Nullable @CheckForNull static Instant toInstant(@Nullable @CheckForNull Object source); static List<String> toList(@Nullable @CheckForNull Object source); static void setConversionService(ConversionService conversionService); }
DataConverter { @Nullable @CheckForNull public static String toString(@Nullable @CheckForNull Object source) { if (source == null) { return null; } if (source instanceof String) { return (String) source; } if (source instanceof Iterable<?>) { StringBuilder sb = new StringBuilder(); for (Object obj : (Iterable<?>) source) { if (sb.length() > 0) sb.append(","); sb.append(toString(obj)); } return sb.toString(); } return convert(source, String.class); } private  DataConverter(); static Object convert(Object source, Attribute attr); @Nullable @CheckForNull static String toString(@Nullable @CheckForNull Object source); @Nullable @CheckForNull static Integer toInt(@Nullable @CheckForNull Object source); @Nullable @CheckForNull static Long toLong(@Nullable @CheckForNull Object source); @SuppressWarnings("java:S2447") // null is a valid return value @Nullable @CheckForNull static Boolean toBoolean(@Nullable @CheckForNull Object source); @Nullable @CheckForNull static Double toDouble(@Nullable @CheckForNull Object source); @Nullable @CheckForNull static LocalDate toLocalDate(@Nullable @CheckForNull Object source); @Nullable @CheckForNull static Instant toInstant(@Nullable @CheckForNull Object source); static List<String> toList(@Nullable @CheckForNull Object source); static void setConversionService(ConversionService conversionService);  }