コード例 #1
0
 protected void assertType(Object ob, Class<?> expType) {
   if (ob == null) {
     fail("Expected an object of type " + expType.getName() + ", got null");
   }
   Class<?> cls = ob.getClass();
   if (!expType.isAssignableFrom(cls)) {
     fail("Expected type " + expType.getName() + ", got " + cls.getName());
   }
 }
コード例 #2
0
  @SuppressWarnings("unchecked")
  public static <T> T convert(Context context, Class<T> type) {
    if (type.isAssignableFrom(Context.class)) {
      return (T) context;
    }
    if (type.isAssignableFrom(Map.class)) {
      return (T) context.keyValues();
    }
    if (isUrlEncodedForm(context)) {
      return convertValue(context.keyValues(), type);
    }

    String json;
    try {
      json = context.request().getContent();
    } catch (IOException e) {
      throw new IllegalArgumentException("Unable read request content", e);
    }

    return fromJson(json, type);
  }