@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); }
private static boolean isUrlEncodedForm(Context context) { String contentType = context.getHeader("Content-Type"); return (contentType != null) && (contentType.contains("application/x-www-form-urlencoded")); }