Created
December 22, 2010 14:40
-
-
Save lucascs/751591 to your computer and use it in GitHub Desktop.
support for VRaptor2's @out annotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Documented | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target(ElementType.FIELD) | |
public @interface Out { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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