Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ protected SqlDateSerializer(Boolean useTimestamp) {
super(java.sql.Date.class, useTimestamp, null);
}

protected SqlDateSerializer(Boolean useTimestamp, DateFormat customFormat) {
super(java.sql.Date.class, useTimestamp, customFormat);
}

@Override
public SqlDateSerializer withFormat(Boolean timestamp, DateFormat customFormat) {
return new SqlDateSerializer(timestamp);
return new SqlDateSerializer(timestamp, customFormat);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ static class SqlDateAsNumberBean {
public SqlDateAsNumberBean(long l) { date = new java.sql.Date(l); }
}

static class SqlDateAsStringBean {
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy.MM.dd")
public java.sql.Date date;
public SqlDateAsStringBean(long l) { date = new java.sql.Date(l); }
}

static class DateAsStringBean {
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd")
public Date date;
Expand Down Expand Up @@ -245,6 +251,10 @@ public void testDateWithJsonFormat() throws Exception
// and with default (ISO8601) format (databind#1109)
json = mapper.writeValueAsString(new DateAsDefaultStringBean(0L));
assertEquals("{\"date\":\"1970-01-01T00:00:00.000+0000\"}", json);

// and with sqlDate format with pattern [Issue#1407]
json = mapper.writeValueAsString(new SqlDateAsStringBean(0L));
assertEquals("{\"date\":\"1970.01.01\"}", json);
}

/**
Expand Down