You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 3, 2019. It is now read-only.
java.util.Date is serialized to epoch milliseconds by default; OffsetDateTime - to epoch seconds. That makes migration to Java 8 date classes exceedingly complicated.
The text was updated successfully, but these errors were encountered:
Assume you have a data type with a "date" field. You want to serve instances of the type via REST API.
If you use legacy java.util.Date class for the "date" field, in the JSON generated by Dropwizard you will see the "date" field represented as a long integer with the value of "milliseconds since Unix epoch", e.g. 1444664056000. That's not very human-readable, but kind of acceptable. Epoch millis are pretty standard, many JS frontends are able to deal with that.
Assume someone told you java.util.Date is terrible and it's a good policy to never ever use it (which happens to be true). You listen and convert all the date types in your application to OffsetDateTime introduced in Java 8.
But now your "date" values are returned by in JSON as SECONDS since Unix epoch, e.g. 1444664056. This causes your frontend to interpret them as dates in early 1970. Sorrow and lamentation.
What's worse, it's not exactly obvious how to configure the date conversion.
java.util.Date is serialized to epoch milliseconds by default; OffsetDateTime - to epoch seconds. That makes migration to Java 8 date classes exceedingly complicated.
The text was updated successfully, but these errors were encountered: