I have a Servlet for handling Ajax requests which gives response in JSON-format.
I get this warning on line as commented below. Type safety: The method setResponseData(Object) belongs to the raw type JsonResponse. References to generic type JsonResponse should be parameterized
Should I be doing this another way, or is it safe to add SuppressWarning annotation
public class JsonResponse<T>
{
private T responseData;
private boolean success;
private String errorMessage;
// + Getters and Setters
}
public class AjaxJson extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
{
String function = request.getParameter("func");
if (function == null)
function = "";
JsonResponse<?> jsonResponse;
if (function.equals("getUsers"))
getUsers(jsonResponse);
}
private void getUsers(JsonResponse jsonResponse)
{
jsonResponse = new JsonResponse<List<User>>();
// Lets say I have a class called User
List<User> users = new ArrayList<Users>();
// get users and add to list
jsonResponse.setResponseData(users); // Warning on this line
jsonResponse.setSuccess(true);
}
}