use of org.springframework.core.convert.ConversionService in project spring-boot by spring-projects.
the class SpringApplication method bindToSpringApplication.
/**
* Bind the environment to the {@link SpringApplication}.
* @param environment the environment to bind
*/
protected void bindToSpringApplication(ConfigurableEnvironment environment) {
PropertiesConfigurationFactory<SpringApplication> binder = new PropertiesConfigurationFactory<>(this);
ConversionService conversionService = new DefaultConversionService();
binder.setTargetName("spring.main");
binder.setConversionService(conversionService);
binder.setPropertySources(environment.getPropertySources());
try {
binder.bindPropertiesToTarget();
} catch (BindException ex) {
throw new IllegalStateException("Cannot bind to SpringApplication", ex);
}
}
use of org.springframework.core.convert.ConversionService in project spring-framework by spring-projects.
the class ConversionServiceFactoryBeanTests method createDefaultConversionService.
@Test
public void createDefaultConversionService() {
ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
factory.afterPropertiesSet();
ConversionService service = factory.getObject();
assertTrue(service.canConvert(String.class, Integer.class));
}
use of org.springframework.core.convert.ConversionService in project spring-framework by spring-projects.
the class DefaultConversionService method addCollectionConverters.
/**
* Add collection converters.
* @param converterRegistry the registry of converters to add to (must also be castable to ConversionService,
* e.g. being a {@link ConfigurableConversionService})
* @throws ClassCastException if the given ConverterRegistry could not be cast to a ConversionService
* @since 4.2.3
*/
public static void addCollectionConverters(ConverterRegistry converterRegistry) {
ConversionService conversionService = (ConversionService) converterRegistry;
converterRegistry.addConverter(new ArrayToCollectionConverter(conversionService));
converterRegistry.addConverter(new CollectionToArrayConverter(conversionService));
converterRegistry.addConverter(new ArrayToArrayConverter(conversionService));
converterRegistry.addConverter(new CollectionToCollectionConverter(conversionService));
converterRegistry.addConverter(new MapToMapConverter(conversionService));
converterRegistry.addConverter(new ArrayToStringConverter(conversionService));
converterRegistry.addConverter(new StringToArrayConverter(conversionService));
converterRegistry.addConverter(new ArrayToObjectConverter(conversionService));
converterRegistry.addConverter(new ObjectToArrayConverter(conversionService));
converterRegistry.addConverter(new CollectionToStringConverter(conversionService));
converterRegistry.addConverter(new StringToCollectionConverter(conversionService));
converterRegistry.addConverter(new CollectionToObjectConverter(conversionService));
converterRegistry.addConverter(new ObjectToCollectionConverter(conversionService));
converterRegistry.addConverter(new StreamConverter(conversionService));
}
use of org.springframework.core.convert.ConversionService in project spring-framework by spring-projects.
the class MediaTypeTests method testWithConversionService.
@Test
public void testWithConversionService() {
ConversionService conversionService = new DefaultConversionService();
assertTrue(conversionService.canConvert(String.class, MediaType.class));
MediaType mediaType = MediaType.parseMediaType("application/xml");
assertEquals(mediaType, conversionService.convert("application/xml", MediaType.class));
}
use of org.springframework.core.convert.ConversionService in project spring-framework by spring-projects.
the class InitBinderDataBinderFactoryTests method createBinderWithGlobalInitialization.
@Test
public void createBinderWithGlobalInitialization() throws Exception {
ConversionService conversionService = new DefaultFormattingConversionService();
bindingInitializer.setConversionService(conversionService);
WebDataBinderFactory factory = createFactory("initBinder", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, null);
assertSame(conversionService, dataBinder.getConversionService());
}
Aggregations