Skip to content

Commit

Permalink
optimize performance
Browse files Browse the repository at this point in the history
  • Loading branch information
liweinan authored and asoldano committed Jan 20, 2019
1 parent 75a1733 commit a4702fc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Expand Up @@ -33,7 +33,7 @@
* The method has to be present in the current JavaScript environment.
* </p>
* <p>
* Jackson JSON processor can produce such an response. This interceptor checks if the media type is a JavaScript one if there is a query
* Jackson JSON decoratorMatcher can produce such an response. This interceptor checks if the media type is a JavaScript one if there is a query
* parameter with the method name. The default name of this query parameter is "callback". So this interceptor is compatible with
* <a href="http://api.jquery.com/jQuery.ajax/">jQuery</a>.
* </p>
Expand Down
Expand Up @@ -51,10 +51,8 @@
public class ResteasyJackson2Provider extends JacksonJaxbJsonProvider
{

public static DecoratedEntityContainer decorateEntity(Class type, Annotation[] annotations, MediaType mediaType, DecoratedEntityContainer container) {
DecoratorMatcher processor = new DecoratorMatcher();
return processor.decorate(DecoratedEntityContainer.class, container, type, annotations, mediaType);
}
DecoratorMatcher decoratorMatcher = new DecoratorMatcher();


@Override
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType)
Expand Down Expand Up @@ -264,7 +262,9 @@ public ClassLoader run()
}

// [RESTEASY-1317] Support Jackson in Atom links
decorateEntity(type, annotations, mediaType, new DecoratedEntityContainer(value));
if (decoratorMatcher.hasDecorator(DecoratedEntityContainer.class, annotations)) {
decoratorMatcher.decorate(DecoratedEntityContainer.class, new DecoratedEntityContainer(value), type, annotations, mediaType);
}

if (System.getSecurityManager() == null) {
writer.writeValue(jg, value);
Expand Down
Expand Up @@ -85,6 +85,15 @@ public <T> T decorate(Class<T> targetClass, T target, Class type, Annotation[] a
return target;
}

public <T> boolean hasDecorator(Class<T> targetClass, Annotation[] annotations) {
for (Annotation annotation : annotations) {
Decorator decorator = annotation.annotationType().getAnnotation(Decorator.class);
if (decorator != null && targetClass.isAssignableFrom(decorator.target()))
return true;
}
return false;
}

private <T> void registerDecorators(Class<T> targetClass, HashMap<Class<?>, Annotation> meta, Annotation[] annotations) {
for (Annotation annotation : annotations)
{
Expand Down
Expand Up @@ -89,16 +89,19 @@ public void after(){
}

@Test
public void testLinks() throws Exception
{
{
public void testLinksXML() throws Exception {

Book book = client.getBookXML("foo");
checkBookLinks1(url, book);
}
{

}

@Test
public void testLinksJson() throws Exception {

Book book = client.getBookJSON("foo");
checkBookLinks1(url, book);
}

}

@Test
Expand Down

0 comments on commit a4702fc

Please sign in to comment.