Skip to content

Commit

Permalink
delegating conversion to MN ConversionService
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Aug 24, 2020
1 parent 39a9a22 commit 80d1f13
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.micronaut.context.env.DefaultEnvironment;
import io.micronaut.core.convert.ArgumentConversionContext;
import io.micronaut.core.convert.ConversionService;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
Expand Down Expand Up @@ -114,9 +115,10 @@ public boolean containsProperties(@Nullable String name) {
@Override
public <T> Optional<T> getProperty(@Nullable String name, ArgumentConversionContext<T> conversionContext) {
Class<T> type = conversionContext.getArgument().getType();
T value = environment.getProperty(name, type);
if (value != null) {
return Optional.of(value);
Object property = environment.getProperty(name, Object.class);
Optional<T> value = ConversionService.SHARED.convert(property, type, conversionContext);
if (value.isPresent()) {
return value;
}

Set<String> alternativeNames = customizer.getAlternativeNames(name);
Expand All @@ -125,9 +127,10 @@ public <T> Optional<T> getProperty(@Nullable String name, ArgumentConversionCont
}

for (String alternativeName : alternativeNames) {
T alternativeValue = environment.getProperty(alternativeName, type);
if (alternativeValue != null) {
return Optional.of(alternativeValue);
Object altProperty = environment.getProperty(alternativeName, Object.class);
Optional<T> alternativeValue = ConversionService.SHARED.convert(altProperty, type, conversionContext);
if (alternativeValue.isPresent()) {
return alternativeValue;
}
}

Expand Down

0 comments on commit 80d1f13

Please sign in to comment.