use of org.springframework.format.support.FormattingConversionService in project spring-data-document-examples by spring-projects.
the class HandlerAdapterConfiguration method conversionService.
@Bean
public ConversionService conversionService() {
FormattingConversionServiceFactoryBean fb = new FormattingConversionServiceFactoryBean();
fb.afterPropertiesSet();
FormattingConversionService cs = fb.getObject();
return cs;
}
use of org.springframework.format.support.FormattingConversionService in project spring-boot by spring-projects.
the class WebMvcAutoConfigurationTests method customDateFormat.
@Test
void customDateFormat() {
this.contextRunner.withPropertyValues("spring.mvc.format.date:dd*MM*yyyy").run((context) -> {
FormattingConversionService conversionService = context.getBean(FormattingConversionService.class);
Date date = Date.from(ZonedDateTime.of(1988, 6, 25, 20, 30, 0, 0, ZoneId.systemDefault()).toInstant());
assertThat(conversionService.convert(date, String.class)).isEqualTo("25*06*1988");
});
}
use of org.springframework.format.support.FormattingConversionService in project spring-boot by spring-projects.
the class WebMvcAutoConfigurationTests method defaultDateTimeFormat.
@Test
void defaultDateTimeFormat() {
this.contextRunner.run((context) -> {
FormattingConversionService conversionService = context.getBean(FormattingConversionService.class);
LocalDateTime dateTime = LocalDateTime.of(2020, 4, 28, 11, 43, 10);
assertThat(conversionService.convert(dateTime, String.class)).isEqualTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).format(dateTime));
});
}
use of org.springframework.format.support.FormattingConversionService in project spring-boot by spring-projects.
the class WebMvcAutoConfigurationTests method defaultDateFormat.
@Test
void defaultDateFormat() {
this.contextRunner.run((context) -> {
FormattingConversionService conversionService = context.getBean(FormattingConversionService.class);
Date date = Date.from(ZonedDateTime.of(1988, 6, 25, 20, 30, 0, 0, ZoneId.systemDefault()).toInstant());
// formatting conversion service should use simple toString()
assertThat(conversionService.convert(date, String.class)).isEqualTo(date.toString());
});
}
use of org.springframework.format.support.FormattingConversionService in project spring-boot by spring-projects.
the class WebMvcAutoConfigurationTests method customDateTimeTimeFormat.
@Test
void customDateTimeTimeFormat() {
this.contextRunner.withPropertyValues("spring.mvc.format.date-time=yyyy-MM-dd HH:mm:ss").run((context) -> {
FormattingConversionService conversionService = context.getBean(FormattingConversionService.class);
LocalDateTime dateTime = LocalDateTime.of(2020, 4, 28, 11, 43, 10);
assertThat(conversionService.convert(dateTime, String.class)).isEqualTo("2020-04-28 11:43:10");
});
}
Aggregations