public T convertValue()

in stetho/src/main/java/com/facebook/stetho/json/ObjectMapper.java [64:95]


  public <T> T convertValue(Object fromValue, Class<T> toValueType)
      throws IllegalArgumentException {
    if (fromValue == null) {
      return null;
    }

    if (toValueType != Object.class
        && toValueType.isAssignableFrom(fromValue.getClass())) {
      return (T) fromValue;
    }

    try {
      if (fromValue instanceof JSONObject) {
        return _convertFromJSONObject((JSONObject) fromValue, toValueType);
      } else if (toValueType == JSONObject.class) {
        return (T) _convertToJSONObject(fromValue);
      } else {
        throw new IllegalArgumentException(
            "Expecting either fromValue or toValueType to be a JSONObject");
      }
    } catch (NoSuchMethodException e) {
      throw new IllegalArgumentException(e);
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException(e);
    } catch (InstantiationException e) {
      throw new IllegalArgumentException(e);
    } catch (JSONException e) {
      throw new IllegalArgumentException(e);
    } catch (InvocationTargetException e) {
      throw ExceptionUtil.propagate(e.getCause());
    }
  }