@Test public void testStringToDate() throws Exception { Date date = CoerceUtil.coerce("1", Date.class); assertEquals(new Date(1), date); java.sql.Date date1 = CoerceUtil.coerce("1", java.sql.Date.class); assertEquals(new java.sql.Date(1), date1); Timestamp timestamp = CoerceUtil.coerce("1", Timestamp.class); assertEquals(new Timestamp(1), timestamp); Time time = CoerceUtil.coerce("1", Time.class); assertEquals(new Time(1), time); }
public static <T> T coerce(Object value, Class<T> cls) { initializeCurrentClassLoaderIfNecessary(); if (value == null || cls == null || cls.isInstance(value)) { return (T) value; } try { return (T) ConvertUtils.convert(value, cls); } catch (ConversionException | InvalidAttributeException | IllegalArgumentException e) { throw new InvalidValueException(value, e.getMessage()); } }
CoerceUtil { public static <T> T coerce(Object value, Class<T> cls) { initializeCurrentClassLoaderIfNecessary(); if (value == null || cls == null || cls.isInstance(value)) { return (T) value; } try { return (T) ConvertUtils.convert(value, cls); } catch (ConversionException | InvalidAttributeException | IllegalArgumentException e) { throw new InvalidValueException(value, e.getMessage()); } } }
CoerceUtil { public static <T> T coerce(Object value, Class<T> cls) { initializeCurrentClassLoaderIfNecessary(); if (value == null || cls == null || cls.isInstance(value)) { return (T) value; } try { return (T) ConvertUtils.convert(value, cls); } catch (ConversionException | InvalidAttributeException | IllegalArgumentException e) { throw new InvalidValueException(value, e.getMessage()); } }  }
CoerceUtil { public static <T> T coerce(Object value, Class<T> cls) { initializeCurrentClassLoaderIfNecessary(); if (value == null || cls == null || cls.isInstance(value)) { return (T) value; } try { return (T) ConvertUtils.convert(value, cls); } catch (ConversionException | InvalidAttributeException | IllegalArgumentException e) { throw new InvalidValueException(value, e.getMessage()); } }  static T coerce(Object value, Class<T> cls); static void register(Class<T> targetType, Serde<S, T> serde); static Serde<S, T> lookup(Class<T> targetType); static Map<Class<?>, Serde<?, ?>> getSerdes(); }
CoerceUtil { public static <T> T coerce(Object value, Class<T> cls) { initializeCurrentClassLoaderIfNecessary(); if (value == null || cls == null || cls.isInstance(value)) { return (T) value; } try { return (T) ConvertUtils.convert(value, cls); } catch (ConversionException | InvalidAttributeException | IllegalArgumentException e) { throw new InvalidValueException(value, e.getMessage()); } }  static T coerce(Object value, Class<T> cls); static void register(Class<T> targetType, Serde<S, T> serde); static Serde<S, T> lookup(Class<T> targetType); static Map<Class<?>, Serde<?, ?>> getSerdes();  }