docs: @SuppressWarnings("unchecked")
    protected <T> T toPrimitiveJavaType(String json, Class<T> type) {
  
      // cleanup the json string
      if (json.length() > 1 && json.startsWith("\"") && json.endsWith("\"")) {
        json = json.replaceFirst("\"", "");
        json = json.substring(0, json.length() - 1);
      }
  
      if (String.class.equals(type)) {
        return (T) json;
      }
      if (Integer.class.equals(type) || Integer.TYPE.equals(type)) {
        return (T) Integer.valueOf(json);
      }
      if (Boolean.class.equals(type) || Boolean.TYPE.equals(type)) {
        return (T) Boolean.valueOf(json);
      }
      if (Long.class.equals(type) || Long.TYPE.equals(type)) {
        return (T) Long.valueOf(json);
      }
      if (Double.class.equals(type) || Double.TYPE.equals(type)) {
        return (T) Double.valueOf(json);
      }
      if (Float.class.equals(type) || Float.TYPE.equals(type)) {
        return (T) Float.valueOf(json);
      }
      if (BigInteger.class.equals(type)) {
        return (T) new BigInteger(json);
      }
      if (BigDecimal.class.equals(type)) {
        return (T) new BigDecimal(json);
      }
  
      throw new FacebookJsonMappingException("Don't know how to map JSON to " + type
          + ". Are you sure you're mapping to the right class?\nOffending JSON is '" + json + "'.");
    }