When run on Tomcat6 or Tomcat7 or WAS7, the following code is always printing out the internal java.util.Date property as yyyy-MM-DD format instead of millisecond format.
ObjectMapper om = new ObjectMapper();
System.out.println(om.writeValueAsString(myObject));
When running standalone, the above code prints out the correct millisecond format.
Is there anything that server could be doing to interfere? I am using Jackson 2.0.6 and Spring 3.1.2 here.
Result:
I found out the issue was that my Date object was getting java.sql.Date. I guess you will not get a timestamp if you’re using java.sql.Date.
The Jackson serialization config may be being stepped on in a number of places including spring and/or hibernate as described here: Where do I specify Jackson SerializationConfig.Feature settings in Spring 3.1
There are probably more correct solutions to stop Spring/Hibernate from doing what they are doing, but if it were up to me, I would just do the following: