I\'m trying to modify Firebase\'s Android chat example to include Firebase timestamp values. I can send the timestamp just fine using ServerValue.TIMESTAMP;
but
I know this thread is quite old, but for anyone trying to implement a similar timestamp now, instead of using @JsonIgnore
from the Jackson annotations, you can use the Firebase native @Exclude
now.
Firebase.ServerValue.TIMESTAMP
is set as a Map (containing {.sv: "timestamp"}
) which tells Firebase to populate that field with the server's time. When that data is read back, it is the actual unix time stamp which is a Long
. When Firebase (using Jackson) tries to deserialize that returned value, it fails since it is not a Map
.
You could use Jackson annotations to control how your class is converted to JSON.
For example, something like this should work:
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.firebase.client.ServerValue;
public class Thing {
private String id;
private Long creationDate;
public Thing() {
}
public Thing(String id) {
this.id = id;
}
public String getId() {
return id;
}
public java.util.Map<String, String> getCreationDate() {
return ServerValue.TIMESTAMP;
}
@JsonIgnore
public Long getCreationDateLong() {
return creationDate;
}
public void setId(String id) {
this.id = id;
}
public void setCreationDate(Long creationDate) {
this.creationDate = creationDate;
}
}