I'm using a java.util.Date in spring(3.1) data REST. How can I get the date to print in a human readable form? (e.g. MM/DD/YYYY)?
@Entity
public class MyEntity{
...
@Column(name="A_DATE_COLUMN")
@DateTimeFormat(iso=ISO.DATE)
private Date aDate;
..getters and setters
}
However when i print my entity(after overriding toString), I'm always getting the date as a long. It seems like @DateTimeFormat does not change the behaviour. I also tried different iso formats and that didnt help either.
"aDate" : 1320130800000
Here is my POM file entry for the spring data rest
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>1.0.0.RELEASE</version>
<exclusions>
<exclusion>
<groupId></groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
Any help is much appeciated. PS. Here is the toString Implementation
@Override
public String toString() {
return getClass().getName() + "{"+
"\n\taDate: " + aDate
+ "\n}";
}
@Temporal(TemporalType.TIMESTAMP)docs.oracle.com/javaee/6/api/javax/persistence/Temporal.html@Temporal(TemporalType.TIMESTAMP)in my application and in case if I want the date in a specific format then I use SimpleDateFormat to format it in the way I need