Java Code Examples for org.springframework.format.support.DefaultFormattingConversionService#addConverter()

The following examples show how to use org.springframework.format.support.DefaultFormattingConversionService#addConverter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataBinderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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));
}
 
Example 2
Source File: DataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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));
}
 
Example 3
Source File: MvcTest.java    From friendly-id with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	mockMvcBuilder = standaloneSetup(new FooController(mock(EntityLinks.class)));
	DefaultFormattingConversionService service = new DefaultFormattingConversionService();
	service.addConverter(new StringToUuidConverter());
	mockMvcBuilder.setMessageConverters(jackson2HttpMessageConverter()).setConversionService(service);
	RestAssuredMockMvc.standaloneSetup(mockMvcBuilder);
}
 
Example 4
Source File: DataBinderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 5
Source File: DataConverterTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@BeforeAll
static void setUpBeforeClass() {
  DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
  conversionService.addConverter(new StringToDateConverter());
  conversionService.addConverter(new StringToDateTimeConverter());
  DataConverter.setConversionService(conversionService);
}