@Test void convertDateTime() { Attribute attr = when(mock(Attribute.class).getName()).thenReturn("attr").getMock(); when(attr.getDataType()).thenReturn(DATE_TIME); assertEquals(Instant.parse("2015-05-22T06:12:13Z"), convert("2015-05-22T11:12:13+0500", attr)); }
@SuppressWarnings("unchecked") @Nullable @CheckForNull private static <T> T convert(@Nullable @CheckForNull Object source, Class<T> targetType) { if (source == null) { return null; } if (targetType.isAssignableFrom(source.getClass())) { return (T) source; } try { return getConversionService().convert(source, targetType); } catch (ConversionException e) { throw new DataConversionException(e); } }
DataConverter { @SuppressWarnings("unchecked") @Nullable @CheckForNull private static <T> T convert(@Nullable @CheckForNull Object source, Class<T> targetType) { if (source == null) { return null; } if (targetType.isAssignableFrom(source.getClass())) { return (T) source; } try { return getConversionService().convert(source, targetType); } catch (ConversionException e) { throw new DataConversionException(e); } } }
DataConverter { @SuppressWarnings("unchecked") @Nullable @CheckForNull private static <T> T convert(@Nullable @CheckForNull Object source, Class<T> targetType) { if (source == null) { return null; } if (targetType.isAssignableFrom(source.getClass())) { return (T) source; } try { return getConversionService().convert(source, targetType); } catch (ConversionException e) { throw new DataConversionException(e); } } private  DataConverter(); }
DataConverter { @SuppressWarnings("unchecked") @Nullable @CheckForNull private static <T> T convert(@Nullable @CheckForNull Object source, Class<T> targetType) { if (source == null) { return null; } if (targetType.isAssignableFrom(source.getClass())) { return (T) source; } try { return getConversionService().convert(source, targetType); } catch (ConversionException e) { throw new DataConversionException(e); } } 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 { @SuppressWarnings("unchecked") @Nullable @CheckForNull private static <T> T convert(@Nullable @CheckForNull Object source, Class<T> targetType) { if (source == null) { return null; } if (targetType.isAssignableFrom(source.getClass())) { return (T) source; } try { return getConversionService().convert(source, targetType); } catch (ConversionException e) { throw new DataConversionException(e); } } 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);  }