I am trying to abstract the code in my previous post into a util class. Here's the util class method:
private static Gson gson = new GsonBuilder().create();
public static Class getResponseObject(String resourceResponse, String jsonObject, Class responseClass) {
JSONObject jsonResponse = new JSONObject(resourceResponse);
String jsonResponseToString = jsonResponse.getJSONObject(jsonObject).toString();
return gson.fromJson(jsonResponseToString, responseClass.getClass());
}
And this is the call from another class:
UserIdentifier userIdentifier = ServiceClientUtil.getResponseObject(resourceResponse,
"userIdentifier",
UserIdentifier.class);
But I'm getting the following error:
Error:(68, 76) java: incompatible types: java.lang.Class cannot be converted to app.identity.UserIdentifier
How do I pass in a class object and return the same class object?