Add ApplicationConversionService and fix binder

Create a new `ApplicationConversionService` similar in design to the
DefaultFormattingConversionService from Spring Framework. The new
conversion service provides a central place for custom conversion logic
supported by Spring Boot.

Also replace the `BindingConversionService` with an internal
`BindConverter` class that now invokes the `SimpleTypeConverter`
directly. Binding for `@ConfigurationProperties` has been updated so
that any custom property editors registered with the BeanFactory can
be used.

Fixes gh-12095
This commit is contained in:
Phillip Webb
2018-02-17 08:21:49 -08:00
parent 61f44179cb
commit 20109e27be
75 changed files with 2706 additions and 1354 deletions

View File

@@ -19,9 +19,8 @@ package org.springframework.boot.actuate.endpoint.invoke.convert;
import org.springframework.boot.actuate.endpoint.invoke.OperationParameter;
import org.springframework.boot.actuate.endpoint.invoke.ParameterMappingException;
import org.springframework.boot.actuate.endpoint.invoke.ParameterValueMapper;
import org.springframework.boot.context.properties.bind.convert.BinderConversionService;
import org.springframework.boot.convert.ApplicationConversionService;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.util.Assert;
/**
@@ -39,7 +38,7 @@ public class ConversionServiceParameterValueMapper implements ParameterValueMapp
* Create a new {@link ConversionServiceParameterValueMapper} instance.
*/
public ConversionServiceParameterValueMapper() {
this(createConversionService());
this(ApplicationConversionService.getSharedInstance());
}
/**
@@ -49,7 +48,7 @@ public class ConversionServiceParameterValueMapper implements ParameterValueMapp
*/
public ConversionServiceParameterValueMapper(ConversionService conversionService) {
Assert.notNull(conversionService, "ConversionService must not be null");
this.conversionService = new BinderConversionService(conversionService);
this.conversionService = conversionService;
}
@Override
@@ -63,10 +62,4 @@ public class ConversionServiceParameterValueMapper implements ParameterValueMapp
}
}
private static ConversionService createConversionService() {
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
IsoOffsetDateTimeConverter.registerConverter(conversionService);
return conversionService;
}
}