@SuppressWarnings("unchecked")
  public static <T> T coerceOutput(Object object, Class<T> targetClass)
      throws TemplateOutputCastException
  {
    Class<?> objectClass = object.getClass();
    if (objectClass == targetClass)
    {
      return (T) object;
    }
    if (targetClass.isEnum())
    {
      if (objectClass == String.class)
      {
        return (T) stringToEnum(targetClass, (String) object);
      }
      throw new TemplateOutputCastException("Output " + object + " has type " + object.getClass().getName() + ", and cannot be coerced to enum type " + targetClass.getName());
    }

    return coerceCustomOutput(object, targetClass);
  }
@Test
  public static void testCoerceOutputNumericNumberCases()
  {
    // Double case
    Object object1 = DataTemplateUtil.coerceOutput(1.2, Double.class);
    assertEquals(object1, 1.2);

    // Float case
    Object object2 = DataTemplateUtil.coerceOutput(1.2f, Float.class);
    assertEquals(object2, 1.2f);

    // Integer case
    Object object3 = DataTemplateUtil.coerceOutput(1, Integer.class);
    assertEquals(object3, 1);

    // Long case
    Object object4 = DataTemplateUtil.coerceOutput(1l, Long.class);
    assertEquals(object4, 1l);
  }