From e5f51400423f49e8027809c708d1ad31b3dde42e Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Tue, 2 Jan 2024 15:35:44 +0100 Subject: [PATCH 1/7] Avoid having `TypeConverter` defined as beans --- .../http/server/ConvertersRegistrar.java | 40 +++++++++++++++++++ .../http/server/cors/CorsOriginConverter.java | 4 +- ...ronaut.core.convert.TypeConverterRegistrar | 1 + ...egistrar.java => ConvertersRegistrar.java} | 7 +++- .../http/cookie/SameSiteConverter.java | 5 ++- ...ronaut.core.convert.TypeConverterRegistrar | 2 +- 6 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java create mode 100644 http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar rename http/src/main/java/io/micronaut/http/{MediaTypeConvertersRegistrar.java => ConvertersRegistrar.java} (83%) diff --git a/http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java b/http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java new file mode 100644 index 00000000000..13fb39ff68f --- /dev/null +++ b/http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017-2024 original authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micronaut.http.server; + +import io.micronaut.core.annotation.Internal; +import io.micronaut.core.convert.MutableConversionService; +import io.micronaut.core.convert.TypeConverter; +import io.micronaut.core.convert.TypeConverterRegistrar; +import io.micronaut.http.server.cors.CorsOriginConfiguration; +import io.micronaut.http.server.cors.CorsOriginConverter; + +import java.util.Map; + +/** + * The HTTP server type converters registrar. + * + * @author Denis Stepanov + * @since 4.3.0 + */ +@Internal +public final class ConvertersRegistrar implements TypeConverterRegistrar { + + @Override + public void register(MutableConversionService conversionService) { + conversionService.addConverter(Map.class, CorsOriginConfiguration.class, (TypeConverter) new CorsOriginConverter()); + } +} diff --git a/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java b/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java index baa6cd42f37..dec87697949 100644 --- a/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java +++ b/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java @@ -15,6 +15,7 @@ */ package io.micronaut.http.server.cors; +import io.micronaut.core.annotation.Internal; import io.micronaut.core.convert.ArgumentConversionContext; import io.micronaut.core.convert.ConversionContext; import io.micronaut.core.convert.ImmutableArgumentConversionContext; @@ -23,7 +24,6 @@ import io.micronaut.core.convert.value.ConvertibleValuesMap; import io.micronaut.core.type.Argument; import io.micronaut.http.HttpMethod; -import jakarta.inject.Singleton; import java.util.List; import java.util.Map; @@ -36,7 +36,7 @@ * @author Graeme Rocher * @since 1.0 */ -@Singleton +@Internal public class CorsOriginConverter implements TypeConverter, CorsOriginConfiguration> { private static final String ALLOWED_ORIGINS = "allowed-origins"; diff --git a/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar b/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar new file mode 100644 index 00000000000..cf90c51f9e9 --- /dev/null +++ b/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar @@ -0,0 +1 @@ +io.micronaut.http.server.ConvertersRegistrar diff --git a/http/src/main/java/io/micronaut/http/MediaTypeConvertersRegistrar.java b/http/src/main/java/io/micronaut/http/ConvertersRegistrar.java similarity index 83% rename from http/src/main/java/io/micronaut/http/MediaTypeConvertersRegistrar.java rename to http/src/main/java/io/micronaut/http/ConvertersRegistrar.java index 5dbd5fc0305..cc586da32c5 100644 --- a/http/src/main/java/io/micronaut/http/MediaTypeConvertersRegistrar.java +++ b/http/src/main/java/io/micronaut/http/ConvertersRegistrar.java @@ -19,17 +19,19 @@ import io.micronaut.core.convert.MutableConversionService; import io.micronaut.core.convert.TypeConverterRegistrar; import io.micronaut.core.util.StringUtils; +import io.micronaut.http.cookie.SameSite; +import io.micronaut.http.cookie.SameSiteConverter; import java.util.Optional; /** - * The media type converters registrar. + * The HTTP converters registrar. * * @author Denis Stepanov * @since 3.6.0 */ @Internal -public final class MediaTypeConvertersRegistrar implements TypeConverterRegistrar { +public final class ConvertersRegistrar implements TypeConverterRegistrar { @Override public void register(MutableConversionService conversionService) { @@ -45,5 +47,6 @@ public void register(MutableConversionService conversionService) { } } }); + conversionService.addConverter(CharSequence.class, SameSite.class, new SameSiteConverter()); } } diff --git a/http/src/main/java/io/micronaut/http/cookie/SameSiteConverter.java b/http/src/main/java/io/micronaut/http/cookie/SameSiteConverter.java index 709aa82b95d..cdbfab00b6e 100644 --- a/http/src/main/java/io/micronaut/http/cookie/SameSiteConverter.java +++ b/http/src/main/java/io/micronaut/http/cookie/SameSiteConverter.java @@ -15,10 +15,11 @@ */ package io.micronaut.http.cookie; +import io.micronaut.core.annotation.Internal; import io.micronaut.core.convert.ConversionContext; import io.micronaut.core.convert.TypeConverter; import io.micronaut.core.util.StringUtils; -import jakarta.inject.Singleton; + import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -29,7 +30,7 @@ * @author Sergio del Amo * @since 3.0.1 */ -@Singleton +@Internal public class SameSiteConverter implements TypeConverter { private static final Map CONVERSIONS = new ConcurrentHashMap<>(); diff --git a/http/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar b/http/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar index e18c5aab449..3393f03dae1 100644 --- a/http/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar +++ b/http/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar @@ -1,2 +1,2 @@ -io.micronaut.http.MediaTypeConvertersRegistrar +io.micronaut.http.ConvertersRegistrar io.micronaut.http.converters.SharedHttpConvertersRegistrar From a1f08c99e1ef22954e57505ed9b9af00654f111e Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Tue, 2 Jan 2024 17:20:48 +0100 Subject: [PATCH 2/7] Delete useless test --- .../CorsOriginConverterEnabledSpec.groovy | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 http-server-netty/src/test/groovy/io/micronaut/http/server/netty/cors/CorsOriginConverterEnabledSpec.groovy diff --git a/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/cors/CorsOriginConverterEnabledSpec.groovy b/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/cors/CorsOriginConverterEnabledSpec.groovy deleted file mode 100644 index 825700190d9..00000000000 --- a/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/cors/CorsOriginConverterEnabledSpec.groovy +++ /dev/null @@ -1,19 +0,0 @@ -package io.micronaut.http.server.netty.cors - -import io.micronaut.context.ApplicationContext -import io.micronaut.http.server.cors.CorsOriginConverter -import spock.lang.AutoCleanup -import spock.lang.Shared -import spock.lang.Specification - -class CorsOriginConverterEnabledSpec extends Specification { - - @AutoCleanup - @Shared - ApplicationContext applicationContext = ApplicationContext.run() - - void "CorsOriginConverter is enabled by default"() { - expect: - applicationContext.containsBean(CorsOriginConverter) - } -} From 9bec1e6a467a40096f58d9e9e2cda636c12d8a72 Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Tue, 2 Jan 2024 18:42:38 +0100 Subject: [PATCH 3/7] Add native image config --- .../http/server/ConvertersRegistrar.java | 3 ++- .../native-image.properties | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties diff --git a/http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java b/http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java index 13fb39ff68f..fc63acc6d94 100644 --- a/http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java +++ b/http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java @@ -35,6 +35,7 @@ public final class ConvertersRegistrar implements TypeConverterRegistrar { @Override public void register(MutableConversionService conversionService) { - conversionService.addConverter(Map.class, CorsOriginConfiguration.class, (TypeConverter) new CorsOriginConverter()); + CorsOriginConverter corsOriginConverter = new CorsOriginConverter(); + conversionService.addConverter(Map.class, CorsOriginConfiguration.class, (TypeConverter) corsOriginConverter); } } diff --git a/http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties b/http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties new file mode 100644 index 00000000000..454d03e22dc --- /dev/null +++ b/http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties @@ -0,0 +1,17 @@ +# +# Copyright 2017-2020 original authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +Args = --initialize-at-build-time=io.micronaut.http.server.cors.CorsOriginConverter From 36e7e184e2489229323ff470cad3bd051f9e0d01 Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Wed, 3 Jan 2024 12:50:43 +0100 Subject: [PATCH 4/7] Address CR --- ...ersRegistrar.java => HttpServerTypeConvertersRegistrar.java} | 2 +- .../services/io.micronaut.core.convert.TypeConverterRegistrar | 2 +- ...ConvertersRegistrar.java => HttpTypeConverterRegistrar.java} | 2 +- .../services/io.micronaut.core.convert.TypeConverterRegistrar | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename http-server/src/main/java/io/micronaut/http/server/{ConvertersRegistrar.java => HttpServerTypeConvertersRegistrar.java} (93%) rename http/src/main/java/io/micronaut/http/{ConvertersRegistrar.java => HttpTypeConverterRegistrar.java} (95%) diff --git a/http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java b/http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java similarity index 93% rename from http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java rename to http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java index fc63acc6d94..c8c076a0646 100644 --- a/http-server/src/main/java/io/micronaut/http/server/ConvertersRegistrar.java +++ b/http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java @@ -31,7 +31,7 @@ * @since 4.3.0 */ @Internal -public final class ConvertersRegistrar implements TypeConverterRegistrar { +public final class HttpServerTypeConvertersRegistrar implements TypeConverterRegistrar { @Override public void register(MutableConversionService conversionService) { diff --git a/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar b/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar index cf90c51f9e9..47985f0d442 100644 --- a/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar +++ b/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar @@ -1 +1 @@ -io.micronaut.http.server.ConvertersRegistrar +io.micronaut.http.server.HttpServerTypeConvertersRegistrar diff --git a/http/src/main/java/io/micronaut/http/ConvertersRegistrar.java b/http/src/main/java/io/micronaut/http/HttpTypeConverterRegistrar.java similarity index 95% rename from http/src/main/java/io/micronaut/http/ConvertersRegistrar.java rename to http/src/main/java/io/micronaut/http/HttpTypeConverterRegistrar.java index cc586da32c5..78f5ea817ee 100644 --- a/http/src/main/java/io/micronaut/http/ConvertersRegistrar.java +++ b/http/src/main/java/io/micronaut/http/HttpTypeConverterRegistrar.java @@ -31,7 +31,7 @@ * @since 3.6.0 */ @Internal -public final class ConvertersRegistrar implements TypeConverterRegistrar { +public final class HttpTypeConverterRegistrar implements TypeConverterRegistrar { @Override public void register(MutableConversionService conversionService) { diff --git a/http/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar b/http/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar index 3393f03dae1..698a81c0a1a 100644 --- a/http/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar +++ b/http/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar @@ -1,2 +1,2 @@ -io.micronaut.http.ConvertersRegistrar +io.micronaut.http.HttpTypeConverterRegistrar io.micronaut.http.converters.SharedHttpConvertersRegistrar From 121ee266a468085a23d2aeaa287114876f188d5b Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Wed, 3 Jan 2024 13:23:52 +0100 Subject: [PATCH 5/7] Deprecate `CorsOriginConverter` --- .../HttpServerTypeConvertersRegistrar.java | 41 ------------------- .../http/server/cors/CorsOriginConverter.java | 2 + .../native-image.properties | 17 -------- ...ronaut.core.convert.TypeConverterRegistrar | 1 - 4 files changed, 2 insertions(+), 59 deletions(-) delete mode 100644 http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java delete mode 100644 http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties delete mode 100644 http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar diff --git a/http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java b/http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java deleted file mode 100644 index c8c076a0646..00000000000 --- a/http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017-2024 original authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micronaut.http.server; - -import io.micronaut.core.annotation.Internal; -import io.micronaut.core.convert.MutableConversionService; -import io.micronaut.core.convert.TypeConverter; -import io.micronaut.core.convert.TypeConverterRegistrar; -import io.micronaut.http.server.cors.CorsOriginConfiguration; -import io.micronaut.http.server.cors.CorsOriginConverter; - -import java.util.Map; - -/** - * The HTTP server type converters registrar. - * - * @author Denis Stepanov - * @since 4.3.0 - */ -@Internal -public final class HttpServerTypeConvertersRegistrar implements TypeConverterRegistrar { - - @Override - public void register(MutableConversionService conversionService) { - CorsOriginConverter corsOriginConverter = new CorsOriginConverter(); - conversionService.addConverter(Map.class, CorsOriginConfiguration.class, (TypeConverter) corsOriginConverter); - } -} diff --git a/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java b/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java index dec87697949..72dbfd0ef86 100644 --- a/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java +++ b/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java @@ -35,7 +35,9 @@ * @author James Kleeh * @author Graeme Rocher * @since 1.0 + * @deprecated The converter is not needed */ +@Deprecated(forRemoval = true, since = "4.3.0") @Internal public class CorsOriginConverter implements TypeConverter, CorsOriginConfiguration> { diff --git a/http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties b/http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties deleted file mode 100644 index 454d03e22dc..00000000000 --- a/http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 2017-2020 original authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Args = --initialize-at-build-time=io.micronaut.http.server.cors.CorsOriginConverter diff --git a/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar b/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar deleted file mode 100644 index 47985f0d442..00000000000 --- a/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar +++ /dev/null @@ -1 +0,0 @@ -io.micronaut.http.server.HttpServerTypeConvertersRegistrar From fb8a28459fcb9c94c035cd0ed425e606652e8860 Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Wed, 3 Jan 2024 15:58:12 +0100 Subject: [PATCH 6/7] Revert "Deprecate `CorsOriginConverter`" This reverts commit 121ee266a468085a23d2aeaa287114876f188d5b. --- .../HttpServerTypeConvertersRegistrar.java | 41 +++++++++++++++++++ .../http/server/cors/CorsOriginConverter.java | 2 - .../native-image.properties | 17 ++++++++ ...ronaut.core.convert.TypeConverterRegistrar | 1 + 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java create mode 100644 http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties create mode 100644 http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar diff --git a/http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java b/http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java new file mode 100644 index 00000000000..c8c076a0646 --- /dev/null +++ b/http-server/src/main/java/io/micronaut/http/server/HttpServerTypeConvertersRegistrar.java @@ -0,0 +1,41 @@ +/* + * Copyright 2017-2024 original authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micronaut.http.server; + +import io.micronaut.core.annotation.Internal; +import io.micronaut.core.convert.MutableConversionService; +import io.micronaut.core.convert.TypeConverter; +import io.micronaut.core.convert.TypeConverterRegistrar; +import io.micronaut.http.server.cors.CorsOriginConfiguration; +import io.micronaut.http.server.cors.CorsOriginConverter; + +import java.util.Map; + +/** + * The HTTP server type converters registrar. + * + * @author Denis Stepanov + * @since 4.3.0 + */ +@Internal +public final class HttpServerTypeConvertersRegistrar implements TypeConverterRegistrar { + + @Override + public void register(MutableConversionService conversionService) { + CorsOriginConverter corsOriginConverter = new CorsOriginConverter(); + conversionService.addConverter(Map.class, CorsOriginConfiguration.class, (TypeConverter) corsOriginConverter); + } +} diff --git a/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java b/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java index 72dbfd0ef86..dec87697949 100644 --- a/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java +++ b/http-server/src/main/java/io/micronaut/http/server/cors/CorsOriginConverter.java @@ -35,9 +35,7 @@ * @author James Kleeh * @author Graeme Rocher * @since 1.0 - * @deprecated The converter is not needed */ -@Deprecated(forRemoval = true, since = "4.3.0") @Internal public class CorsOriginConverter implements TypeConverter, CorsOriginConfiguration> { diff --git a/http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties b/http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties new file mode 100644 index 00000000000..454d03e22dc --- /dev/null +++ b/http-server/src/main/resources/META-INF/native-image/io.micronaut/micronaut-http-server/native-image.properties @@ -0,0 +1,17 @@ +# +# Copyright 2017-2020 original authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +Args = --initialize-at-build-time=io.micronaut.http.server.cors.CorsOriginConverter diff --git a/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar b/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar new file mode 100644 index 00000000000..47985f0d442 --- /dev/null +++ b/http-server/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar @@ -0,0 +1 @@ +io.micronaut.http.server.HttpServerTypeConvertersRegistrar From 96e086a1986e59b10f1d20678296a43f0fb3565a Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Wed, 3 Jan 2024 16:16:14 +0100 Subject: [PATCH 7/7] Correct docs --- src/main/docs/guide/config/customTypeConverter.adoc | 2 +- src/main/docs/guide/httpServer/binding.adoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/docs/guide/config/customTypeConverter.adoc b/src/main/docs/guide/config/customTypeConverter.adoc index 44049955bbf..a31c9f190d9 100644 --- a/src/main/docs/guide/config/customTypeConverter.adoc +++ b/src/main/docs/guide/config/customTypeConverter.adoc @@ -23,4 +23,4 @@ snippet::io.micronaut.docs.config.converters.MapToLocalDateConverter[tags="impor <3> The implementation delegates to the injected conversion service to convert the values from the Map used to create a `LocalDate` <4> If an exception occurs during binding, call `reject(..)` which propagates additional information to the container -NOTE: Register new type converters by declaring a bean of type api:core.convert.TypeConverter[]. `ConversionService.SHARED` is deprecated, and it will be removed in a future version of the Micronaut Framework. +NOTE: It's possible to add a custom type converter into `ConversionService.SHARED` by registering it in a api:core.convert.TypeConverterRegistrar[] via the service loader. diff --git a/src/main/docs/guide/httpServer/binding.adoc b/src/main/docs/guide/httpServer/binding.adoc index 2c681f8f2d7..abbcdc2cdf1 100644 --- a/src/main/docs/guide/httpServer/binding.adoc +++ b/src/main/docs/guide/httpServer/binding.adoc @@ -90,7 +90,7 @@ WARNING: Since Java does not retain argument names in bytecode, you must compile Generally any type that can be converted from a String representation to a Java type via the link:{api}/io/micronaut/core/convert/ConversionService.html[ConversionService] API can be bound to. -This includes most common Java types, however additional link:{api}/io/micronaut/core/convert/TypeConverter.html[TypeConverter] instances can be registered via the service loader or by creating beans of type `TypeConverter`, +This includes most common Java types. However, you can simply add additional link:{api}/io/micronaut/core/convert/TypeConverter.html[TypeConverter] either by defining it as a bean or by registering it in a api:core.convert.TypeConverterRegistrar[] via the service loader. The handling of nullability deserves special mention. Consider for example the following example: