Skip to content

Instantly share code, notes, and snippets.

@kramer65
Created September 26, 2013 11:06
Show Gist options
  • Save kramer65/6712716 to your computer and use it in GitHub Desktop.
Save kramer65/6712716 to your computer and use it in GitHub Desktop.
Serializer for Joda DateTime with ActiveAndroid ORM.
package com.activeandroid.serializer;
import org.joda.time.DateTime;
public final class JodaDateTimeSerializer extends TypeSerializer {
public Class<?> getDeserializedType() {
return DateTime.class;
}
public Class<?> getSerializedType() {
return long.class;
}
public Long serialize(Object data) {
if (data == null) {
return null;
}
return ((DateTime) data).getMillis();
}
public DateTime deserialize(Object data) {
if (data == null) {
return null;
}
return new DateTime().withMillis((Long)data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment