Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Caerbannog/a68c75979f4e9c92b60497bad01ebdc9 to your computer and use it in GitHub Desktop.
Save Caerbannog/a68c75979f4e9c92b60497bad01ebdc9 to your computer and use it in GitHub Desktop.
Google Firebase Database, serialize and unserialize a ServerValue.TIMESTAMP with the same Model
```java
// Model
public class User {
public Object timestamp; // Server time.
...
}
// Example code
public void test() {
// Save
user.timestamp = ServerValue.TIMESTAMP;
FirebaseDatabase...setValue(user);
// Load
FirebaseDatabase...addListenerForSingleValueEvent(DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
...
if (user.timestamp instanceof Long) {
Timber.w("read_value = %s", (Long) user.timestamp);
}
else {
Timber.e("Unexpected timestamp type for %s", user.timestamp);
}
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment