@Test public void testBasicHappyPath() { Assert.assertTrue(ValueNormalizationUtil.convertString(Integer.class, null) == null); Assert.assertTrue(ValueNormalizationUtil.convertString(String.class, "foo").equals("foo")); Assert.assertTrue(ValueNormalizationUtil.convertString(Integer.class, "5").equals(Integer.valueOf(5))); Assert.assertTrue(ValueNormalizationUtil.convertString(Long.class, "5").equals(Long.valueOf(5))); Assert.assertTrue(ValueNormalizationUtil.convertString(int.class, "5").equals(Integer.valueOf(5))); Assert.assertTrue(ValueNormalizationUtil.convertString(long.class, "5").equals(Long.valueOf(5))); Assert.assertTrue(ValueNormalizationUtil.convertString(Boolean.class, "true").equals(Boolean.TRUE)); }
public static Object convertString(Class targetType, String value) { Validate.notNull(targetType, "Null targetType not allowed."); if (value == null) { return value; } if (ClassUtils.isAssignable(targetType, String.class)) { return value; } if (ClassUtils.isAssignable(targetType, Integer.class)) { return Integer.valueOf(value); } if (ClassUtils.isAssignable(targetType, int.class)) { return Integer.valueOf(value); } if (ClassUtils.isAssignable(targetType, Long.class)) { return Long.valueOf(value); } if (ClassUtils.isAssignable(targetType, long.class)) { return Long.valueOf(value); } Boolean bValue = BooleanUtils.toBooleanObject(value); if (bValue != null) { return bValue; } throw new MonetaException("Property type not supported") .addContextValue("targetType", targetType.getName()); }
ValueNormalizationUtil { public static Object convertString(Class targetType, String value) { Validate.notNull(targetType, "Null targetType not allowed."); if (value == null) { return value; } if (ClassUtils.isAssignable(targetType, String.class)) { return value; } if (ClassUtils.isAssignable(targetType, Integer.class)) { return Integer.valueOf(value); } if (ClassUtils.isAssignable(targetType, int.class)) { return Integer.valueOf(value); } if (ClassUtils.isAssignable(targetType, Long.class)) { return Long.valueOf(value); } if (ClassUtils.isAssignable(targetType, long.class)) { return Long.valueOf(value); } Boolean bValue = BooleanUtils.toBooleanObject(value); if (bValue != null) { return bValue; } throw new MonetaException("Property type not supported") .addContextValue("targetType", targetType.getName()); } }
ValueNormalizationUtil { public static Object convertString(Class targetType, String value) { Validate.notNull(targetType, "Null targetType not allowed."); if (value == null) { return value; } if (ClassUtils.isAssignable(targetType, String.class)) { return value; } if (ClassUtils.isAssignable(targetType, Integer.class)) { return Integer.valueOf(value); } if (ClassUtils.isAssignable(targetType, int.class)) { return Integer.valueOf(value); } if (ClassUtils.isAssignable(targetType, Long.class)) { return Long.valueOf(value); } if (ClassUtils.isAssignable(targetType, long.class)) { return Long.valueOf(value); } Boolean bValue = BooleanUtils.toBooleanObject(value); if (bValue != null) { return bValue; } throw new MonetaException("Property type not supported") .addContextValue("targetType", targetType.getName()); }  }
ValueNormalizationUtil { public static Object convertString(Class targetType, String value) { Validate.notNull(targetType, "Null targetType not allowed."); if (value == null) { return value; } if (ClassUtils.isAssignable(targetType, String.class)) { return value; } if (ClassUtils.isAssignable(targetType, Integer.class)) { return Integer.valueOf(value); } if (ClassUtils.isAssignable(targetType, int.class)) { return Integer.valueOf(value); } if (ClassUtils.isAssignable(targetType, Long.class)) { return Long.valueOf(value); } if (ClassUtils.isAssignable(targetType, long.class)) { return Long.valueOf(value); } Boolean bValue = BooleanUtils.toBooleanObject(value); if (bValue != null) { return bValue; } throw new MonetaException("Property type not supported") .addContextValue("targetType", targetType.getName()); }  static Object convertString(Class targetType, String value); }
ValueNormalizationUtil { public static Object convertString(Class targetType, String value) { Validate.notNull(targetType, "Null targetType not allowed."); if (value == null) { return value; } if (ClassUtils.isAssignable(targetType, String.class)) { return value; } if (ClassUtils.isAssignable(targetType, Integer.class)) { return Integer.valueOf(value); } if (ClassUtils.isAssignable(targetType, int.class)) { return Integer.valueOf(value); } if (ClassUtils.isAssignable(targetType, Long.class)) { return Long.valueOf(value); } if (ClassUtils.isAssignable(targetType, long.class)) { return Long.valueOf(value); } Boolean bValue = BooleanUtils.toBooleanObject(value); if (bValue != null) { return bValue; } throw new MonetaException("Property type not supported") .addContextValue("targetType", targetType.getName()); }  static Object convertString(Class targetType, String value);  }