JsonString在运行时到JavaObject

时间:2018-05-09 11:36:44

标签: java json

我正在尝试在运行时将JSON String转换为Java Object。有可能吗?



        String className = errorInfo.getClassName();
		String methodName = errorInfo.getMethodName();
		String requestMessage = errorInfo.getMessage();
		String reference3 = errorInfo.getReference3();

		try {
			Class claz = Class.forName(className);
			Object obj = claz.newInstance();
			Class[] parameterTypes = new Class[1];
			parameterTypes[0] = Class.forName(reference3).getClass();
			Method method = claz.getMethod(methodName, parameterTypes);
			method.invoke(obj, new      
            ObjectMapper().readValue(requestMessage,<I have to pass here .class reference>>));
          }
          catch(Exception ex)
{
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我犯了一个基本错误。以下代码为我工作:

function() {
  if (    ) return {{GA Settings 1}};
  return {{GA Settings 2}};
}