Using quarkus-resteasy-jsonb for my RESTful service
and with this class
public class MyEnvelopeClass<T> {
private T content;
public MyEnvelopeClass(T content) {
this.content = content;
}
public T getContent() {
return content;
}
}
Returned from this resource method:
@GET
@Path("/{id}")
public MyEnvelopeClass<MyPayloadClass> getById(@PathParam("id") String id){
return new MyEnvelopeClass<MyPayloadClass>(new MyPayloadClass());
}
The result from my GET request returns the correct payload, however, I get this warning in the log each time the request is made.
2019-08-15 12:25:36,477 WARNING [org.ecl.yas.int.ReflectionUtils] (executor-thread-1) Generic bound not found for type T declared in class MyEnvelopeClass.
If I switch to quarkus-resteasy-jackson, the warning is not logged. ( however I have to include other dependencies to get "Instant" to serialize properly, and configure the ObjectMapper to use it... Then I end up with Maven warnings too... so I would prefer to stick with the jsonb dependency )
If I change my code to use an anonymous inner class, extending MyEnvelopeClass with the Generic type... the warning is not logged:
@GET
@Path("/{id}")
public MyEnvelopeClass<MyPayloadClass> getById(@PathParam("id") String id){
return new MyEnvelopeClass<MyPayloadClass>(new MyPayloadClass()){};
}
I can use this as a workaround, but I would rather fix the issue holistically rather than within every single Resource method we write.
Thanks!
-sean
Environment (please complete the following information):
uname -a or ver:Output of java -version:
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.3+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)
GraalVM version (if different from Java):
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-20190711112007.graal.jdk8u-src-tar-gz-b08)
OpenJDK 64-Bit GraalVM CE 19.1.1 (build 25.222-b08-jvmci-19.1-b01, mixed mode)
Quarkus version or git rev:
Also, I just tried to run in Native mode. And neither option above produces output from my endpoint. just '''{}''' is returned
More Information. Turns out the anonymous class is merely changing the behavior of what is being logged for the very first request after a hot-redeploy. ( Adding the {} makes the first request not get logged with a warning, but subsequent ones do )
So the anonymous class was just a red herring. I always get the warning.
Adding @RegisterForReflection Fixed the issue with Native mode. Generics must not be supported in the Quarkus auto-registration?
So the only issue seems to be the noisy warning message
I opened #3557 to handle the case you mentioned about needing @RegisterForReflection - that should not be necessary.
As for the log message, it is coming from Yasson, not sure what we could do about it.
@geoand well, it could be a Yasson issue or a RESTEasy issue (with RESTEasy not providing the correct information to Yasson).
@sean-scott-lr could you try to reproduce the issue with simple Yasson code. If you can reproduce it then it's likely a Yasson issue and it should be reported here: https://github.com/eclipse-ee4j/yasson/issues
@gsmet I will give it a shot, but this week will be tough because my schedule is packed.
...edit
Googled how to use the Yasson API, and it looked easy... so I went ahead and just added this to an endpoint that wasn't generating a warning.
JsonbConfig config = new JsonbConfig() .withNullValues(false);
Jsonb jsonb = JsonbBuilder.create(config);
String result = jsonb.toJson(new MyEnvelopeClass<MyPayloadClass>(new MyPayloadClass()));
System.out.println( result );
Yep, this bit of code generates the warning. I will open an issue on Yasson.
FYI I've delivered the fix for this issue in Yasson which will be included in the next release (1.0.6)
@gsmet go ahead and assign this issue to me please. I can use it as a ticket to upgrade Quarkus to Yasson 1.0.6 when it gets released
@aguibert any idea when 1.0.6 will be released ?
@rsvoboda it's been a while since we released Yasson 1.0.5 so I suppose we're about due for a new release. I'll work on cutting a new Yasson release this week and getting Quarkus updated
Most helpful comment
FYI I've delivered the fix for this issue in Yasson which will be included in the next release (1.0.6)