quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

add support on quarkus-rest-links for classes generated by Immutables from an interface #41807

Open cvgaviao opened 3 months ago

cvgaviao commented 3 months ago

Description

I'm using Immutable to generate some immutable DTOs.

public interface UserDto extends Serializable {

    @Nullable
    @InjectId
    @Id
    Long getId();
}

I also created an @InjectId annotation to instruct Immutables to add the @Id on the generated class.

public final class ImmutableUserDto implements UserDto {
  @Id
  private final @Nullable Long id;

But I still getting this error:

Caused by: java.lang.IllegalStateException: Cannot generate web links for the class myproject.dtos.UserDto because it is either missing anidfield, a field with an@Idannotation or a field with a@RestLinkId annotation

Implementation ideas

No response

gastaldi commented 2 months ago

Can you please provide a small reproducer?

cvgaviao commented 1 month ago

Hello @gastaldi ,

I think I found a workaround / solution for this problem.

We should inform the concrete class on the entityType parameter of @RestLink: @RestLink(entityType = ImmutableUserDto.class)

I will proper test it as soon I return from vacation.

geoand commented 1 month ago

@cvgaviao where you perhaps able to test your fix?

cvgaviao commented 1 month ago

Hello @geoand,

I tested it today.

Besides using the fact that using the entityType property of @RestLink have prevented it to give an error, it not work as expected: I didn't see any link on the response.

Maybe it is because I'm using Immutables and its builders, and it unfortunately doesn't allow us to generate public constructors.

geoand commented 1 month ago

Thanks for the update.

Can you please provide a small reproducer?

Uping this :)

geoand commented 3 weeks ago

Let's close this for now. If a reproducer becomes available, please attach it and we can reopen the issue

cvgaviao commented 3 weeks ago

Let's close this for now. If a reproducer becomes available, please attach it and we can reopen the issue

Sorry. I will do that in the next weekend. things are in a rush here in my job recently.

geoand commented 3 weeks ago

👌

cvgaviao commented 3 weeks ago

Hello @geoand , there is the reproducer.

Try to call 'http://localhost:8080/users/1' and you see the error I got. But now the error is different than the one I got when I created this issue though (use of entityType = ImmutableUserDto.class).

java.lang.NullPointerException: 
Cannot invoke "java.util.Map.get(Object)" because the return value of "java.util.Map.get(Object)" is null
        at io.quarkus.resteasy.reactive.links.runtime.GetterAccessorsContainer.get(GetterAccessorsContainer.java:14)
        at io.quarkus.resteasy.reactive.links.runtime.RestLinksProviderImpl.getPathParameterValues(RestLinksProviderImpl.java:65)
        at io.quarkus.resteasy.reactive.links.runtime.RestLinksProviderImpl.getInstanceLinks(RestLinksProviderImpl.java:57)
        at io.quarkus.resteasy.reactive.links.RestLinksProviderProducer_ProducerMethod_restLinksProvider_eGzDuhQoSV1-UbOUneVkE4POzbM_ClientProxy.getInstanceLinks(Unknown Source)
        at io.quarkus.resteasy.reactive.links.RestLinksHandler.getLinks(RestLinksHandler.java:38)
        at io.quarkus.resteasy.reactive.links.RestLinksHandler.handle(RestLinksHandler.java:29)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:150)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
        at org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1$1.handle(VertxResteasyReactiveRequestContext.java:84)
        at org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1$1.handle(VertxResteasyReactiveRequestContext.java:81)
        at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:270)
        at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:252)
        at io.vertx.core.impl.ContextInternal.lambda$runOnContext$0(ContextInternal.java:50)
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:1583)

quarkus-restlink-and-db-constraint-issue.zip

geoand commented 3 weeks ago

Thanks, I'll have a look soon

geoand commented 1 week ago

cc @Sgitario