Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid having TypeConverter defined as beans #10315

Merged
merged 7 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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.
sdelamo marked this conversation as resolved.
Show resolved Hide resolved
*
* @author Denis Stepanov
* @since 4.3.0
*/
@Internal
public final class ConvertersRegistrar implements TypeConverterRegistrar {

@Override
public void register(MutableConversionService conversionService) {
CorsOriginConverter corsOriginConverter = new CorsOriginConverter();
conversionService.addConverter(Map.class, CorsOriginConfiguration.class, (TypeConverter) corsOriginConverter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -36,7 +36,7 @@
* @author Graeme Rocher
* @since 1.0
*/
@Singleton
@Internal
public class CorsOriginConverter implements TypeConverter<Map<String, Object>, CorsOriginConfiguration> {

private static final String ALLOWED_ORIGINS = "allowed-origins";
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.micronaut.http.server.ConvertersRegistrar
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
sdelamo marked this conversation as resolved.
Show resolved Hide resolved

@Override
public void register(MutableConversionService conversionService) {
Expand All @@ -45,5 +47,6 @@ public void register(MutableConversionService conversionService) {
}
}
});
conversionService.addConverter(CharSequence.class, SameSite.class, new SameSiteConverter());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +30,7 @@
* @author Sergio del Amo
* @since 3.0.1
*/
@Singleton
@Internal
public class SameSiteConverter implements TypeConverter<CharSequence, SameSite> {
private static final Map<CharSequence, SameSite> CONVERSIONS = new ConcurrentHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
io.micronaut.http.MediaTypeConvertersRegistrar
io.micronaut.http.ConvertersRegistrar
io.micronaut.http.converters.SharedHttpConvertersRegistrar
Loading