jLuger.de - Fun with Java EE, JavaScript and date

Recently I had some fun with dates while developing an app with a JavaEE Backend and a JavaScript Frontend. Here are my notes about it.

java.sql.Date stays to it's name and stores only dates but no times (at least with wildfly 9.0.2). See also the entry in the javadoc:
"To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero..."

While date is often enough some times you also need a time. E.g. for things like lastupdated or created. Here you have to use java.util.Date or java.util.Calendar. I've choosen java.util.Date.

When transformed to Json the java.util.Date becomes a long value which isn't very intuitive while debuging. When using Jackson (like I did with wildfly 9.0.2) there is an annotation to change this: JsonFormat. Add the following dependency to your pom.xml:
		<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>

Then add the following annotation above your date fields:
	@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSSX")
private Date done;

The pattern you see above wasn't my first one. I've used it after I've created a date in JavaScript and my Backend refused to accept it. When creating a date the JavaScript console in Firefox I get:
new Date()
Date 2016-06-14T19:51:53.317Z