Skip to content

Instantly share code, notes, and snippets.

@lucascs
Created Dec 22, 2010
Embed
What would you like to do?
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