use of org.springframework.core.convert.support.GenericConversionService in project spring-framework by spring-projects.
the class DefaultMessageHandlerMethodFactoryTests method customConversion.
@Test
public void customConversion() throws Exception {
DefaultMessageHandlerMethodFactory instance = createInstance();
GenericConversionService conversionService = new GenericConversionService();
conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() {
@Override
public String convert(SampleBean source) {
return "foo bar";
}
});
instance.setConversionService(conversionService);
instance.afterPropertiesSet();
InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class);
invocableHandlerMethod.invoke(MessageBuilder.withPayload(sample).build());
assertMethodInvocation(sample, "simpleString");
}
use of org.springframework.core.convert.support.GenericConversionService in project spring-data-document-examples by spring-projects.
the class RestaurantController method registerConverters.
@InitBinder
void registerConverters(WebDataBinder binder) {
if (binder.getConversionService() instanceof GenericConversionService) {
GenericConversionService conversionService = (GenericConversionService) binder.getConversionService();
conversionService.addConverter(getRestaurantConverter());
}
}
use of org.springframework.core.convert.support.GenericConversionService in project spring-data-document-examples by spring-projects.
the class SignUpController method registerConverters.
@InitBinder
void registerConverters(WebDataBinder binder) {
if (binder.getConversionService() instanceof GenericConversionService) {
GenericConversionService conversionService = (GenericConversionService) binder.getConversionService();
conversionService.addConverter(getRestaurantConverter());
conversionService.addConverter(getUserAccountConverter());
conversionService.addConverter(getRestaurantConverterFromString());
}
}
use of org.springframework.core.convert.support.GenericConversionService in project grails-core by grails.
the class AbstractGrailsPluginManager method doRuntimeConfiguration.
/**
* Base implementation that simply goes through the list of plugins and calls doWithRuntimeConfiguration on each
* @param springConfig The RuntimeSpringConfiguration instance
*/
public void doRuntimeConfiguration(RuntimeSpringConfiguration springConfig) {
ApplicationContext context = springConfig.getUnrefreshedApplicationContext();
AutowireCapableBeanFactory autowireCapableBeanFactory = context.getAutowireCapableBeanFactory();
if (autowireCapableBeanFactory instanceof ConfigurableListableBeanFactory) {
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) autowireCapableBeanFactory;
ConversionService existingConversionService = beanFactory.getConversionService();
ConverterRegistry converterRegistry;
if (existingConversionService == null) {
GenericConversionService conversionService = new GenericConversionService();
converterRegistry = conversionService;
beanFactory.setConversionService(conversionService);
} else {
converterRegistry = (ConverterRegistry) existingConversionService;
}
converterRegistry.addConverter(new Converter<NavigableMap.NullSafeNavigator, Object>() {
@Override
public Object convert(NavigableMap.NullSafeNavigator source) {
return null;
}
});
}
checkInitialised();
for (GrailsPlugin plugin : pluginList) {
if (plugin.supportsCurrentScopeAndEnvironment() && plugin.isEnabled(context.getEnvironment().getActiveProfiles())) {
plugin.doWithRuntimeConfiguration(springConfig);
}
}
}
use of org.springframework.core.convert.support.GenericConversionService in project spring-framework by spring-projects.
the class ApplicationContextExpressionTests method prototypeCreationReevaluatesExpressions.
@Test
public void prototypeCreationReevaluatesExpressions() {
GenericApplicationContext ac = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
GenericConversionService cs = new GenericConversionService();
cs.addConverter(String.class, String.class, new Converter<String, String>() {
@Override
public String convert(String source) {
return source.trim();
}
});
ac.getBeanFactory().registerSingleton(GenericApplicationContext.CONVERSION_SERVICE_BEAN_NAME, cs);
RootBeanDefinition rbd = new RootBeanDefinition(PrototypeTestBean.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
rbd.getPropertyValues().add("country", "#{systemProperties.country}");
rbd.getPropertyValues().add("country2", new TypedStringValue("-#{systemProperties.country}-"));
ac.registerBeanDefinition("test", rbd);
ac.refresh();
try {
System.getProperties().put("name", "juergen1");
System.getProperties().put("country", " UK1 ");
PrototypeTestBean tb = (PrototypeTestBean) ac.getBean("test");
assertEquals("juergen1", tb.getName());
assertEquals("UK1", tb.getCountry());
assertEquals("-UK1-", tb.getCountry2());
System.getProperties().put("name", "juergen2");
System.getProperties().put("country", " UK2 ");
tb = (PrototypeTestBean) ac.getBean("test");
assertEquals("juergen2", tb.getName());
assertEquals("UK2", tb.getCountry());
assertEquals("-UK2-", tb.getCountry2());
} finally {
System.getProperties().remove("name");
System.getProperties().remove("country");
}
}
Aggregations