Skip to content

Instantly share code, notes, and snippets.

@lucascs
Created December 22, 2010 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascs/751591 to your computer and use it in GitHub Desktop.
Save lucascs/751591 to your computer and use it in GitHub Desktop.
support for VRaptor2's @out annotation
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Out {
}
@Intercepts(after=ExecuteMethodInterceptor.class, before=ForwardToDefaultViewInterceptor.class)
public class OutAnnotationInterceptor implements Interceptor {
public OutAnnotationInterceptor(Result result) {
this.result = result;
}
public boolean accepts(ResourceMethod method) { return true; }
public void intercept(InterceptorStack stack, ResourceMethod method, Object instance) {
List<Field> fields = new Mirror().on(ResourceMethod.class).reflectAll().fields();
for (Field field : fields) {
if (field.isAnnotationPresent(Out.class))
result.include(field.getName(), new Mirror().on(instance).get().field(field));
}
stack.next(method, instance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment