Skip to content

Commit

Permalink
Avoid having TypeConverter defined as beans
Browse files Browse the repository at this point in the history
  • Loading branch information
dstepanov committed Jan 2, 2024
1 parent 530fe91 commit 80839b2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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());
}
}
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 @@
io.micronaut.http.s
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 {

@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

0 comments on commit 80839b2

Please sign in to comment.