title: How to implement Jersey middleware for custom Processing of JSON entity request body
body: <p>I'd like to log JSON request entity bodies for all POST requests to all resources in a <strong>Dropwizard</strong> Application of mine. The catch is that I need to resolve the request's type, make a copy of the entity, and do some custom request field formatting before the entity is logged. I also cannot change the request's Class or the Field's Class in anyway (even with Annotations). </p>
  
  <p>How do I leverage the logic that Jersey and Jackson use for resolving the Java POJO class type before the request is passed into the Resource? </p>
  
  <p>Should I use <strong>Filters</strong>, <strong>Interceptors</strong>, or <strong>EventListener</strong> implementations?</p>
  
  <pre><code>// I need to create raw JSON for instances of this class where fields
  // of type Location get specially formatted but only for logging.
  // i.e doesn't affect normal structure of the request
  class CustomRequest {
      // In the raw JSON i create this field's name should be converted
      // to 'origin_geo' and its value should be a float with the first
      // value being the longitude and the second element being the 
      // latitude.
      public Location origin;
  
      public String otherField;
  }
  
  interface Location {
      float getLongitude();
      float getLatitude();    
  }
  </code></pre>
  
  <p>For other Applications to leverage the middleware, I want to avoid needing to create special code for each different request type. I want something generic that is able to recognize Location typed fields for any entity and simply serialize the entity but with modification to those Location typed fields.</p>
  
  <p>Does anyone know the right way to do this with the frameworks at play? I believe Jersey is able to use reflection to resolve the type when the resource method is resolved by looking at the method's parameters and choosing the first parameter that satisfies some set of conditions. I would like to avoid reimplementing this.</p>