use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class ServletModelAttributeMethodProcessorTests method setup.
@Before
public void setup() throws Exception {
processor = new ServletModelAttributeMethodProcessor(false);
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
binderFactory = new ServletRequestDataBinderFactory(null, initializer);
mavContainer = new ModelAndViewContainer();
request = new MockHttpServletRequest();
webRequest = new ServletWebRequest(request);
Method method = getClass().getDeclaredMethod("modelAttribute", TestBean.class, TestBeanWithoutStringConstructor.class, Optional.class);
testBeanModelAttr = new MethodParameter(method, 0);
testBeanWithoutStringConstructorModelAttr = new MethodParameter(method, 1);
testBeanWithOptionalModelAttr = new MethodParameter(method, 2);
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method optionalMultipartFileWithoutMultipartRequest.
@Test
public void optionalMultipartFileWithoutMultipartRequest() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
Object actual = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertEquals(Optional.empty(), actual);
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveOptionalParamValue.
@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamValue() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, Integer.class);
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertEquals(Optional.empty(), result);
this.request.addParameter("name", "123");
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertEquals(Optional.class, result.getClass());
assertEquals(123, ((Optional) result).get());
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-boot by spring-projects.
the class SecurityPropertiesTests method init.
@Before
public void init() {
this.binder.setIgnoreUnknownFields(false);
this.binder.setConversionService(new DefaultConversionService());
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-boot by spring-projects.
the class ConfigurationPropertiesBindingPostProcessor method getDefaultConversionService.
private ConversionService getDefaultConversionService() {
if (this.defaultConversionService == null) {
DefaultConversionService conversionService = new DefaultConversionService();
this.applicationContext.getAutowireCapableBeanFactory().autowireBean(this);
for (Converter<?, ?> converter : this.converters) {
conversionService.addConverter(converter);
}
for (GenericConverter genericConverter : this.genericConverters) {
conversionService.addConverter(genericConverter);
}
this.defaultConversionService = conversionService;
}
return this.defaultConversionService;
}
Aggregations