I am a bit confused with @RegisterForReflection
and when does Quarkus
actually require it as my application runs perfectly fine in dev or in native mode without it.
In a simple PoC application I have added a quarkus-rest-client-jackson
and access the gravatar
/profile
api.
Client looks like:
@RegisterRestClient(configKey = "gravatar")
public interface GravatarClient {
@GET
@Path("/v3/profiles/{id}")
GravatarProfile findById(@PathParam("id") String id);
}
and the model
@Getter
@Builder
@Jacksonized
@ToString
public class GravatarProfile {
@JsonProperty("first_name")
private final String firstName;
@JsonProperty("last_name")
private final String lastName;
@JsonProperty("profile_url")
private final String url;
@JsonProperty("registration_date")
private final ZonedDateTime registrationDate;
@Builder.Default
@JsonProperty("verified_accounts")
private final List<Account> verifiedAccounts = List.of();
@Getter
@Builder
@Jacksonized
@ToString
public static class Account {
@JsonProperty("service_type")
private final String type;
}
}
In both native
and dev
mode the deserialization works flawlessly. Based on the documentation I would have expected an exception such like:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.acme.jsonb.Person and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
Why is it working? and when should I be careful not forgetting this annotation?
Quarkus will automatically register a class like yours for reflection if it is part of the method signature of a known integration point. For example, if the class is a return type of JAX-RS / Jakarta REST method, that type will automatically be registered for reflection