January 9, 2012
Java: Joda DateTime on the wire, long values in the database

I’ve begun development of the Android app for Batch and we use REST/JSON as our API.

Dates in JSON are represented as strings like:

2012-01-07T01:06:37Z

I am also using the wonderful ORMLite framework to persist my objects in a local SQLite database. I would like to store my dates as UNIX timestamps using a type of “long”. By doing this I can do date filtering much faster by just having SQLite compare numbers instead of strings.

Thus, I need an easy and transparent way to marshal my dates from DateTime strings to Longs and back and forth. 

Fortunately I am using the Jackson JSON library which has killer custom serialization/deserialization support. 

  1. ruckus posted this