Add support for YearMonth and MonthDay in @DateTimeFormat
See gh-1215
This commit is contained in:
committed by
Stephane Nicoll
parent
a9d2016007
commit
65eceafeee
@@ -64,6 +64,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Juergen Hoeller
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
* @author Kazuki Shimizu
|
||||
*/
|
||||
class DateTimeFormattingTests {
|
||||
|
||||
@@ -467,6 +468,16 @@ class DateTimeFormattingTests {
|
||||
assertThat(binder.getBindingResult().getFieldValue("yearMonth").toString().equals("2007-12")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindYearMonthAnnotatedPattern() {
|
||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||
propertyValues.add("yearMonthAnnotatedPattern", "12/2007");
|
||||
binder.bind(propertyValues);
|
||||
assertEquals(0, binder.getBindingResult().getErrorCount());
|
||||
assertTrue(binder.getBindingResult().getFieldValue("yearMonthAnnotatedPattern").toString().equals("12/2007"));
|
||||
assertEquals(YearMonth.parse("2007-12"), binder.getBindingResult().getRawFieldValue("yearMonthAnnotatedPattern"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBindMonthDay() {
|
||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||
@@ -557,6 +568,16 @@ class DateTimeFormattingTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindMonthDayAnnotatedPattern() {
|
||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||
propertyValues.add("monthDayAnnotatedPattern", "1/3");
|
||||
binder.bind(propertyValues);
|
||||
assertEquals(0, binder.getBindingResult().getErrorCount());
|
||||
assertTrue(binder.getBindingResult().getFieldValue("monthDayAnnotatedPattern").toString().equals("1/3"));
|
||||
assertEquals(MonthDay.parse("--01-03"), binder.getBindingResult().getRawFieldValue("monthDayAnnotatedPattern"));
|
||||
}
|
||||
|
||||
|
||||
public static class DateTimeBean {
|
||||
|
||||
@@ -611,6 +632,12 @@ class DateTimeFormattingTests {
|
||||
|
||||
private YearMonth yearMonth;
|
||||
|
||||
@DateTimeFormat(pattern="MM/uuuu")
|
||||
private YearMonth yearMonthAnnotatedPattern;
|
||||
|
||||
@DateTimeFormat(pattern="M/d")
|
||||
private MonthDay monthDayAnnotatedPattern;
|
||||
|
||||
private MonthDay monthDay;
|
||||
|
||||
private final List<DateTimeBean> children = new ArrayList<>();
|
||||
@@ -775,6 +802,14 @@ class DateTimeFormattingTests {
|
||||
this.yearMonth = yearMonth;
|
||||
}
|
||||
|
||||
public YearMonth getYearMonthAnnotatedPattern() {
|
||||
return yearMonthAnnotatedPattern;
|
||||
}
|
||||
|
||||
public void setYearMonthAnnotatedPattern(YearMonth yearMonthAnnotatedPattern) {
|
||||
this.yearMonthAnnotatedPattern = yearMonthAnnotatedPattern;
|
||||
}
|
||||
|
||||
public MonthDay getMonthDay() {
|
||||
return this.monthDay;
|
||||
}
|
||||
@@ -783,6 +818,14 @@ class DateTimeFormattingTests {
|
||||
this.monthDay = monthDay;
|
||||
}
|
||||
|
||||
public MonthDay getMonthDayAnnotatedPattern() {
|
||||
return monthDayAnnotatedPattern;
|
||||
}
|
||||
|
||||
public void setMonthDayAnnotatedPattern(MonthDay monthDayAnnotatedPattern) {
|
||||
this.monthDayAnnotatedPattern = monthDayAnnotatedPattern;
|
||||
}
|
||||
|
||||
public List<DateTimeBean> getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user