我正在尝试将 json api 响应映射到一个对象,而 IntelliJ 正在抱怨。它在说cannot resolve method readValue(java.lang.String, java.lang.Object[]);
。我意识到我没有传递正确的参数,但我尝试过但responseClass.class
没有responseClass.getClass()
运气。
用法:
MyClass myClass = new MyClass();
myClass.setResponseClass(User.class);
定义:
MyClass {
private Object responseClass;
public void setResponseClass(Object responseClass) {
this.responseClass = responseClass;
}
public Object getResponseClass() {
return responseClass;
}
public void getApiResponse() {
//some code here
ObjectMapper mapper = new com.MyApp.Utility.ObjectMapper();
//some code here
//I've tried responseClass.class and responseClass.getClass(), it didn't like either of them
mapper.readValue(response, responseClass);
//more code here
}
}