### Question:
TypeUtil { public static <T> T toObjectType(String data, Class<T> klass) { if (Double.class.equals(klass)) { try { return klass.cast(Double.parseDouble(data)); } catch (NumberFormatException ex) { return null; } } else if (Long.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (Integer.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (StringUtils.equalsIgnoreCase("true", data)) { return klass.cast(Boolean.TRUE); } else if (StringUtils.equalsIgnoreCase("false", data)) { return klass.cast(Boolean.FALSE); } else if (JSON_DATE.matcher(data).matches()) { long epochSeconds = OffsetDateTime.parse(data).toInstant().toEpochMilli(); return klass.cast(new Date(epochSeconds)); } else { return klass.cast(data); } } private  TypeUtil(); static Map<T, T> arrayToMap(T[] list); static Map<String, Object> toMap(JsonObject json); @SuppressWarnings({ "unchecked", "PMD.CollapsibleIfStatements" }) static Class<T> getType(final Object object); static T toObjectType(String data, Class<T> klass); static String toString(final Object obj, final Class<?> klass); static String toString(final Object obj, final Class<?> klass, String methodName); static String toString(final Object obj); static ValueMap toValueMap(final Map<String, ?> map);  }### Answer:
@Test public void toObjectType_Double() { assertEquals(Double.valueOf(10.01), TypeUtil.toObjectType("10.01", Double.class)); }
@Test public void toObjectType_Long() { assertEquals(Long.valueOf(10L), TypeUtil.toObjectType("10", Long.class)); }
@Test public void toObjectType_BooleanTrue() { assertEquals(Boolean.TRUE, TypeUtil.toObjectType("true", Boolean.class)); }
@Test public void toObjectType_BooleanFalse() { assertEquals(Boolean.FALSE, TypeUtil.toObjectType("false", Boolean.class)); }
@Test public void toObjectType_Date() { Date expResult = new Date(); expResult.setTime(1000); assertEquals(expResult, TypeUtil.toObjectType("1970-01-01T00:00:01.000+00:00", Date.class)); }
@Test public void toObjectType_String() { String expResult = "Hello World"; assertEquals(expResult, TypeUtil.toObjectType(expResult, String.class)); }