From 313258156c4e074901670d9049b03695c607d2a7 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Fri, 26 Apr 2024 15:20:08 +0100 Subject: [PATCH] Remove mapping @RegisterForReflection --- .../io/quarkus/it/smallrye/config/Alias.java | 6 - .../io/quarkus/it/smallrye/config/Named.java | 6 - .../io/quarkus/it/smallrye/config/Server.java | 45 ---- .../it/smallrye/config/ServerResource.java | 253 +++++++++++++++++- .../io/quarkus/it/smallrye/config/Ssl.java | 7 - 5 files changed, 252 insertions(+), 65 deletions(-) diff --git a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Alias.java b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Alias.java index 83674ecd9918de..ed2322aa791a8f 100644 --- a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Alias.java +++ b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Alias.java @@ -2,12 +2,6 @@ import java.util.Optional; -import com.fasterxml.jackson.annotation.JsonProperty; - -import io.quarkus.runtime.annotations.RegisterForReflection; - -@RegisterForReflection public interface Alias extends Named { - @JsonProperty Optional alias(); } diff --git a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Named.java b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Named.java index 4afc7e8adb472b..df7f4237116681 100644 --- a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Named.java +++ b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Named.java @@ -2,12 +2,6 @@ import java.util.Optional; -import com.fasterxml.jackson.annotation.JsonProperty; - -import io.quarkus.runtime.annotations.RegisterForReflection; - -@RegisterForReflection public interface Named { - @JsonProperty Optional name(); } diff --git a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Server.java b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Server.java index 499354ab42e0e3..88e2a106d65603 100644 --- a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Server.java +++ b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Server.java @@ -14,9 +14,6 @@ import org.eclipse.microprofile.config.spi.Converter; -import com.fasterxml.jackson.annotation.JsonProperty; - -import io.quarkus.runtime.annotations.RegisterForReflection; import io.quarkus.runtime.configuration.DurationConverter; import io.smallrye.config.ConfigMapping; import io.smallrye.config.WithConverter; @@ -25,100 +22,72 @@ import io.smallrye.config.WithParentName; @ConfigMapping(prefix = "http.server") -@RegisterForReflection public interface Server extends Alias { - @JsonProperty String host(); - @JsonProperty @Min(8000) int port(); - @JsonProperty @WithConverter(DurationConverter.class) Duration timeout(); - @JsonProperty @WithName("io-threads") int threads(); @WithConverter(ByteArrayConverter.class) byte[] bytes(); - @JsonProperty @WithParentName Map form(); - @JsonProperty Optional ssl(); - @JsonProperty Optional proxy(); - @JsonProperty Optional cors(); - @JsonProperty Log log(); - @JsonProperty Info info(); - @RegisterForReflection interface Form { - @JsonProperty String loginPage(); - @JsonProperty String errorPage(); - @JsonProperty String landingPage(); - @JsonProperty Optional cookie(); - @JsonProperty @WithDefault("1") List positions(); } - @RegisterForReflection interface Proxy { - @JsonProperty boolean enable(); - @JsonProperty @Max(10) int timeout(); } - @RegisterForReflection interface Log { - @JsonProperty @WithDefault("false") boolean enabled(); - @JsonProperty @WithDefault(".log") String suffix(); - @JsonProperty @WithDefault("true") boolean rotate(); - @JsonProperty @WithDefault("COMMON") Pattern pattern(); - @JsonProperty Period period(); - @JsonProperty @Max(15) int days(); - @RegisterForReflection enum Pattern { COMMON, SHORT, @@ -127,47 +96,33 @@ enum Pattern { } } - @RegisterForReflection interface Cors { - @JsonProperty List origins(); - @JsonProperty List<@Size(min = 2) String> methods(); - @RegisterForReflection interface Origin { - @JsonProperty @Size(min = 5) String host(); - @JsonProperty @Min(8000) int port(); } } - @RegisterForReflection interface Info { - @JsonProperty Optional<@Size(max = 3) String> name(); - @JsonProperty @Max(3) OptionalInt code(); - @JsonProperty Optional> alias(); - @JsonProperty Map> admins(); - @JsonProperty Map> firewall(); - @RegisterForReflection interface Admin { - @JsonProperty @Size(max = 4) String username(); } diff --git a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ServerResource.java b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ServerResource.java index 69205f27a85532..8631c7ffefddfc 100644 --- a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ServerResource.java +++ b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ServerResource.java @@ -1,6 +1,12 @@ package io.quarkus.it.smallrye.config; +import java.time.Duration; +import java.time.Period; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; @@ -15,6 +21,9 @@ import org.eclipse.microprofile.config.inject.ConfigProperties; import org.eclipse.microprofile.config.inject.ConfigProperty; +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.quarkus.runtime.annotations.RegisterForReflection; import io.smallrye.config.ConfigValidationException; import io.smallrye.config.SmallRyeConfig; @@ -36,7 +45,7 @@ public class ServerResource { @GET public Response getServer() { - return Response.ok(server).build(); + return Response.ok(new ServerResponse(server)).build(); } @GET @@ -76,4 +85,246 @@ public String info() { public List positions() { return positions; } + + /** + * This is to avoid having to register the mapping class for reflection, so it does not interfere with Quarkus + * reflection registration and provide accurate results. + */ + @RegisterForReflection + public static class ServerResponse implements Server { + private final Server server; + + public ServerResponse(final Server server) { + this.server = server; + } + + @Override + @JsonProperty + public Optional alias() { + return server.alias(); + } + + @Override + @JsonProperty + public Optional name() { + return server.name(); + } + + @Override + @JsonProperty + public String host() { + return server.host(); + } + + @Override + @JsonProperty + public int port() { + return server.port(); + } + + @Override + public Duration timeout() { + return null; + } + + @Override + @JsonProperty + public int threads() { + return server.threads(); + } + + @Override + public byte[] bytes() { + return new byte[0]; + } + + @Override + @JsonProperty + public Map form() { + Map formResponses = new HashMap<>(); + for (Map.Entry entry : server.form().entrySet()) { + formResponses.put(entry.getKey(), new FormResponse(entry.getValue())); + } + return formResponses; + } + + @Override + @JsonProperty + public Optional ssl() { + return server.ssl().map(SslResponse::new); + } + + @Override + public Optional proxy() { + return Optional.empty(); + } + + @Override + @JsonProperty + public Optional cors() { + return server.cors().map(CorsResponse::new); + } + + @Override + @JsonProperty + public Log log() { + return new LogResponse(server.log()); + } + + @Override + public Info info() { + return null; + } + + @RegisterForReflection + public static class FormResponse implements Form { + private final Form form; + + public FormResponse(final Form form) { + this.form = form; + } + + @Override + @JsonProperty + public String loginPage() { + return form.loginPage(); + } + + @Override + @JsonProperty + public String errorPage() { + return form.errorPage(); + } + + @Override + @JsonProperty + public String landingPage() { + return form.landingPage(); + } + + @Override + public Optional cookie() { + return Optional.empty(); + } + + @Override + @JsonProperty + public List positions() { + return form.positions(); + } + } + + @RegisterForReflection + public static class SslResponse implements Ssl { + private final Ssl ssl; + + public SslResponse(final Ssl ssl) { + this.ssl = ssl; + } + + @Override + @JsonProperty + public int port() { + return ssl.port(); + } + + @Override + @JsonProperty + public String certificate() { + return ssl.certificate(); + } + + @Override + public List protocols() { + return null; + } + } + + @RegisterForReflection + public static class CorsResponse implements Cors { + private final Cors cors; + + public CorsResponse(final Cors cors) { + this.cors = cors; + } + + @Override + @JsonProperty + public List origins() { + return cors.origins().stream().map(OriginResponse::new).collect(Collectors.toList()); + } + + @Override + @JsonProperty + public List methods() { + return cors.methods(); + } + + @RegisterForReflection + public static class OriginResponse implements Origin { + private final Origin origin; + + public OriginResponse(final Origin origin) { + this.origin = origin; + } + + @Override + @JsonProperty + public String host() { + return origin.host(); + } + + @Override + @JsonProperty + public int port() { + return origin.port(); + } + } + } + + @RegisterForReflection + public static class LogResponse implements Log { + private final Log log; + + public LogResponse(final Log log) { + this.log = log; + } + + @Override + @JsonProperty + public boolean enabled() { + return log.enabled(); + } + + @Override + @JsonProperty + public String suffix() { + return log.suffix(); + } + + @Override + @JsonProperty + public boolean rotate() { + return log.rotate(); + } + + @Override + @JsonProperty + public Pattern pattern() { + return log.pattern(); + } + + @Override + @JsonProperty + public Period period() { + return log.period(); + } + + @Override + @JsonProperty + public int days() { + return log.days(); + } + } + } } diff --git a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Ssl.java b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Ssl.java index 57360cf9bccd08..6bd5e77dc08c18 100644 --- a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Ssl.java +++ b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/Ssl.java @@ -2,20 +2,13 @@ import java.util.List; -import com.fasterxml.jackson.annotation.JsonProperty; - -import io.quarkus.runtime.annotations.RegisterForReflection; import io.smallrye.config.WithDefault; -@RegisterForReflection public interface Ssl { - @JsonProperty int port(); - @JsonProperty String certificate(); - @JsonProperty @WithDefault("TLSv1.3,TLSv1.2") List protocols(); }