Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Provider
- @Produces(MediaType.APPLICATION_JSON)
- public class MyObjWriter implements MessageBodyWriter<MyObject> {
- @Override
- public boolean isWriteable(Class<?> type, Type genericType,
- Annotation[] annotations, MediaType mediaType) {
- return MyObject.class.isAssignableFrom(type);
- }
- ...
- }
- @javax.interceptor.Interceptor
- @MyAnn
- public class MyAnnInterceptor {
- @Context
- private Providers providers;
- @AroundInvoke
- public Object aroundServiceMethod(InvocationContext ctx) throws Exception {
- Object myObj = ctx.proceed();
- MessageBodyWriter writer = providers.getMessageBodyWriter(
- myObj.getClass(), myObj.getClass(),
- new Annotation[0], MediaType.APPLICATION_JSON_TYPE);
- // writer is an instance of MyObjWriter only if MyObjWriter
- // is not in a jar (and I need it to work while in a jar).
- ...
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement