Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. @Provider
  2. @Produces(MediaType.APPLICATION_JSON)
  3. public class MyObjWriter implements MessageBodyWriter<MyObject> {
  4.  
  5. @Override
  6. public boolean isWriteable(Class<?> type, Type genericType,
  7. Annotation[] annotations, MediaType mediaType) {
  8.  
  9. return MyObject.class.isAssignableFrom(type);
  10. }
  11.  
  12. ...
  13. }
  14.  
  15. @javax.interceptor.Interceptor
  16. @MyAnn
  17. public class MyAnnInterceptor {
  18.  
  19. @Context
  20. private Providers providers;
  21.  
  22. @AroundInvoke
  23. public Object aroundServiceMethod(InvocationContext ctx) throws Exception {
  24. Object myObj = ctx.proceed();
  25.  
  26. MessageBodyWriter writer = providers.getMessageBodyWriter(
  27. myObj.getClass(), myObj.getClass(),
  28. new Annotation[0], MediaType.APPLICATION_JSON_TYPE);
  29.  
  30. // writer is an instance of MyObjWriter only if MyObjWriter
  31. // is not in a jar (and I need it to work while in a jar).
  32.  
  33. ...
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement