diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/format/WebConversionService.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/format/WebConversionService.java index 65da2183da..078c546711 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/format/WebConversionService.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/format/WebConversionService.java @@ -89,7 +89,7 @@ public class WebConversionService extends DefaultFormattingConversionService { DateTimeFormatterRegistrar dateTime = new DateTimeFormatterRegistrar(); if (this.dateFormat != null) { dateTime.setDateFormatter(DateTimeFormatter.ofPattern(this.dateFormat) - .withResolverStyle(ResolverStyle.STRICT)); + .withResolverStyle(ResolverStyle.SMART)); } dateTime.registerFormatters(this); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/format/WebConversionServiceTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/format/WebConversionServiceTests.java index 611b91717d..0f8a97b444 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/format/WebConversionServiceTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/format/WebConversionServiceTests.java @@ -28,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link WebConversionService}. * * @author Brian Clozel + * @author Madhura Bhave */ public class WebConversionServiceTests { @@ -44,4 +45,12 @@ public class WebConversionServiceTests { .isEqualTo("01*01*2018"); } + @Test + public void convertFromStringToDate() { + WebConversionService conversionService = new WebConversionService("yyyy-MM-dd"); + java.time.LocalDate date = conversionService.convert("2018-01-01", + java.time.LocalDate.class); + assertThat(date).isEqualTo(java.time.LocalDate.of(2018, 1, 1)); + } + }