TypeConverter { public static Boolean convertToBool(final Object value) { if (value instanceof Boolean) { return (Boolean) value; } if (value instanceof Number) { double val = ((Number) value).doubleValue(); return val != 0 && !((Number) val).equals(Double.NaN); } if (value instanceof String) { return !((String) value).isEmpty(); } if (value instanceof List) { return Boolean.TRUE; } return value != null; }  static Boolean convertToBool(final Object value); static Double convertToDouble(final Object value);  }
@Test public void should_ConvertValueToBooleanLikeJavaScript() { assertEquals(true, convertToBool(nonNull)); assertEquals(true, convertToBool(_true)); assertEquals(true, convertToBool(num)); assertEquals(true, convertToBool(nonEmptyStr)); assertEquals(false, convertToBool(_null)); assertEquals(false, convertToBool(_false)); assertEquals(false, convertToBool(nan)); assertEquals(false, convertToBool(zero)); assertEquals(false, convertToBool(emptyStr)); }