Created
September 26, 2013 11:06
-
-
Save kramer65/6712716 to your computer and use it in GitHub Desktop.
Serializer for Joda DateTime with ActiveAndroid ORM.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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