Skip to content

Commit

Permalink
add Decorators annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
liweinan authored and asoldano committed Jan 20, 2019
1 parent 23c9af6 commit 5e9135b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
@@ -0,0 +1,21 @@
package org.jboss.resteasy.annotations;

import org.jboss.resteasy.spi.DecoratorProcessor;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Meta-annotation to be placed on another annotation that triggers decoration
*
* @see DecoratorProcessor
* @see DecorateTypes
*/
@Target({ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Decorators
{
Decorator[] values();
}
Expand Up @@ -99,6 +99,7 @@ public <T> boolean hasDecorator(Class<T> targetClass, Annotation[] annotations)
private <T> void registerDecorators(Class<T> targetClass, HashMap<Class<?>, Annotation> meta, Annotation[] annotations) {
for (Annotation annotation : annotations)
{
Decorators decorators = annotation.annotationType().getAnnotation(Decorators.class);
Decorator decorator = annotation.annotationType().getAnnotation(Decorator.class);
if (decorator != null && targetClass.isAssignableFrom(decorator.target()))
{
Expand Down
@@ -1,7 +1,10 @@
package org.jboss.resteasy.links;

import org.jboss.resteasy.annotations.Decorator;
import org.jboss.resteasy.annotations.Decorators;
import org.jboss.resteasy.links.impl.JsonLinkDecorator;
import org.jboss.resteasy.links.impl.LinkDecorator;
import org.jboss.resteasy.plugins.providers.jackson.DecoratedEntityContainer;

import javax.xml.bind.Marshaller;
import java.lang.annotation.Documented;
Expand All @@ -15,12 +18,16 @@
* to every entity in the response. This will only inject RESTServiceDiscovery instances
* on entities that have a field of this type, but it will be done recursively on the response's
* entity.
*
* @author <a href="mailto:stef@epardaud.fr">Stéphane Épardaud</a>
*/
@Target( { ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER,
ElementType.FIELD })
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER,
ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Decorator(processor = LinkDecorator.class, target = Marshaller.class)
@Decorators(values = {
@Decorator(processor = LinkDecorator.class, target = Marshaller.class),
@Decorator(processor = JsonLinkDecorator.class, target = DecoratedEntityContainer.class)
})
@Documented
public @interface AddLinks {
}

0 comments on commit 5e9135b

Please sign in to comment.