2

I'd like to log JSON request entity bodies for all POST requests to all resources in a Dropwizard 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).

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?

Should I use Filters, Interceptors, or EventListener implementations?

// 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();    
}

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.

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.