@Test public void testNoConversions() throws Exception { assertEquals(1, CoerceUtil.coerce(1, (Class<Object>) null), "coerce returns value if target class null"); assertEquals(null, CoerceUtil.coerce(null, Object.class), "coerce returns value if value is null"); assertEquals(1, (Object) CoerceUtil.coerce(1, int.class), "coerce returns value if value is assignable to target"); }
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();  }