Search in sources :

Example 16 with DefaultFormattingConversionService

use of org.springframework.format.support.DefaultFormattingConversionService in project spring-framework by spring-projects.

the class DataBinderTests method testConversionWithInappropriateStringEditor.

@Test
public void testConversionWithInappropriateStringEditor() {
    DataBinder dataBinder = new DataBinder(null);
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    dataBinder.setConversionService(conversionService);
    dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    NameBean bean = new NameBean("Fred");
    assertEquals("ConversionService should have invoked toString()", "Fred", dataBinder.convertIfNecessary(bean, String.class));
    conversionService.addConverter(new NameBeanConverter());
    assertEquals("Type converter should have been used", "[Fred]", dataBinder.convertIfNecessary(bean, String.class));
}
Also used : StringTrimmerEditor(org.springframework.beans.propertyeditors.StringTrimmerEditor) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) Test(org.junit.Test)

Aggregations

DefaultFormattingConversionService (org.springframework.format.support.DefaultFormattingConversionService)16 Test (org.junit.Test)8 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)7 BindingContext (org.springframework.web.reactive.BindingContext)6 Before (org.junit.Before)4 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)3 FormattingConversionService (org.springframework.format.support.FormattingConversionService)3 Optional (java.util.Optional)2 Bean (org.springframework.context.annotation.Bean)2 MethodParameter (org.springframework.core.MethodParameter)2 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)2 ConversionService (org.springframework.core.convert.ConversionService)2 WebDataBinder (org.springframework.web.bind.WebDataBinder)2 DefaultDataBinderFactory (org.springframework.web.bind.support.DefaultDataBinderFactory)2 Method (java.lang.reflect.Method)1 Instant (java.time.Instant)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 CasConfigurationEmbeddedValueResolver (org.apereo.cas.config.support.CasConfigurationEmbeddedValueResolver)1