There is no direct way I found where jersey can provide me input object ( conversion from json to java object) in Filter as it does in Resource.
Following is the code I used to accomplished it.
You can call this method in your Jersey filter to get Input object.
Following is the code I used to accomplished it.
public<T> T getInputObject(HttpServletRequest request, Class <T> type) { if (request != null && type != null) { try { ServletInputStream inputStream = request.getInputStream(); // Wrap a BufferedReader around the InputStream BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream)); // Read response until the end inputStream.mark(inputStream.available()); StringBuffer total = new StringBuffer(); String line = null; while ((line = rd.readLine()) != null) { total.append(line); } inputStream.reset(); ObjectMapper obm = new ObjectMapper(); return obm.readValue(total.toString(), type); } catch (Exception e) { logback.error("Exception during getting Input Object for jersey filter",e); return null; } } return null; }
You can call this method in your Jersey filter to get Input object.
MyRestInput input=getInputObject(request, MyRestInput .class);