jax-rsmoxydata-transfer-objectsoxm

Is it possible to inject ResourceInfo into EntityProvider, such as MessageBodyReader and MessageBodyWriter?


There is a requirement:

For each RESTful resource method, there is a set of OXM metadata file. I need to load those files while creating JAXBContext. So I need to know per-request ResourceInfo, and then mapping from some Annotation on the Resource Method, which can indicate which set of OXM metadata file should be loaded.

  1. Is ResourceInfo per-request?
  2. Can I obtain the Method (resource method) per request inside EntityProvider, such as MessageBodyReader and MessageBodyWriter?
  3. Which do you prefer, OXM metadata between JPA Entity and XML/JSON or between TO and XML/JSON? Since I assume per service TO can customize the view of domain class to client.

Solution

  • I had similar problem. After several hours of research I got what I want by directly injecting provider capable to resolve resource method:

    @Inject
    Provider<RoutingContext> routingContextProvider;
    
    
        log.info("routing method == " + routingContextProvider.get().getResourceMethod());