Invoker { @SuppressWarnings({ "rawtypes", "unchecked" }) Object convert(Type type, Object value) throws Exception { if (type == Integer.class) { String v = value.toString(); return v.isEmpty() ? null : Integer.parseInt(v); } else if (type == Long.class) { String v = value.toString(); return v.isEmpty() ? null : Long.parseLong(v); } else if (type == String.class) { String v = value.toString().trim(); return v.isEmpty() ? null : v; } ByteArrayInputStream stream = new ByteArrayInputStream(value.toString().getBytes(StandardCharsets.UTF_8)); Class clazz = classOf(type); return webRenderer.readFrom(clazz, type, null, null, null, stream); } @Inject  Invoker(GsonWebRenderer webRenderer, Logger logger); WebResponse invoke(WebRequest request, MatchResult match, Handler handler);  }
@Test public void convertEmptyString() throws Exception { assertEquals(null, invoker.convert(String.class, "")); }