Skip to content

Commit

Permalink
Merge pull request #4223 from stuartwdouglas/register-ref
Browse files Browse the repository at this point in the history
Allow additional classes to be easily registered for reflection
  • Loading branch information
mkouba authored Sep 27, 2019
2 parents e1f7a18 + 03b84b0 commit 35e1bb6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import javax.inject.Inject;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Type;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand All @@ -31,7 +33,15 @@ public void build() throws Exception {
ClassInfo target = i.target().asClass();
boolean methods = i.value("methods") == null || i.value("methods").asBoolean();
boolean fields = i.value("fields") == null || i.value("fields").asBoolean();
reflectiveClass.produce(new ReflectiveClassBuildItem(methods, fields, target.name().toString()));
AnnotationValue targetsValue = i.value("targets");
if (targetsValue == null) {
reflectiveClass.produce(new ReflectiveClassBuildItem(methods, fields, target.name().toString()));
} else {
Type[] targets = targetsValue.asClassArray();
for (Type type : targets) {
reflectiveClass.produce(new ReflectiveClassBuildItem(methods, fields, type.name().toString()));
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@
* If the fields should be registered
*/
boolean fields() default true;

/**
* Alternative classes that should actually be registered for reflection instead of the current class.
*
* This allows for classes in 3rd party libraries to be registered without modification or writing an
* extension. If this is set then the class it is placed on is not registered for reflection, so this should
* generally just be placed on an empty class that is not otherwise used.
*/
Class<?>[] targets() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ public interface MyInterface {
String getName();
}

@RegisterForReflection
public static class MyEntity {
private String name;
private String value;
Expand All @@ -410,6 +409,11 @@ public void setValue(String value) {
}
}

@RegisterForReflection(targets = MyEntity.class)
public static class EmptyClass {

}

public static class MyOpenApiEntityV1 {
private String name;

Expand Down

0 comments on commit 35e1bb6

Please sign in to comment.