Skip to content

Commit f7135ff

Browse files
committed
Use ResolverStyle.SMART when a custom format is specified
Fixes gh-13970
1 parent 51fd27f commit f7135ff

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/format/WebConversionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private void registerJsr310() {
8989
DateTimeFormatterRegistrar dateTime = new DateTimeFormatterRegistrar();
9090
if (this.dateFormat != null) {
9191
dateTime.setDateFormatter(DateTimeFormatter.ofPattern(this.dateFormat)
92-
.withResolverStyle(ResolverStyle.STRICT));
92+
.withResolverStyle(ResolverStyle.SMART));
9393
}
9494
dateTime.registerFormatters(this);
9595
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/format/WebConversionServiceTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* Tests for {@link WebConversionService}.
2929
*
3030
* @author Brian Clozel
31+
* @author Madhura Bhave
3132
*/
3233
public class WebConversionServiceTests {
3334

@@ -44,4 +45,12 @@ public void customDateFormat() {
4445
.isEqualTo("01*01*2018");
4546
}
4647

48+
@Test
49+
public void convertFromStringToDate() {
50+
WebConversionService conversionService = new WebConversionService("yyyy-MM-dd");
51+
java.time.LocalDate date = conversionService.convert("2018-01-01",
52+
java.time.LocalDate.class);
53+
assertThat(date).isEqualTo(java.time.LocalDate.of(2018, 1, 1));
54+
}
55+
4756
}

0 commit comments

Comments
 (0)