Hello I'm starting a new Android project using Firebase real time database.
My problem is when I create a new message, I put created_at = ServerValue.TIMESTAMP
and it's a Map<String,String>
. When I fetch a message I got error parsing telling me that created_at
is a long
and I put it in my model a Map. My code below :
@IgnoreExtraProperties
public class Message implements Serializable
{
@SerializedName("message_id")
@Expose
private String message_id;
@SerializedName("value")
@Expose
private String value;
@SerializedName("sender")
@Expose
private User sender;
@SerializedName("destination")
@Expose
private User destination;
@SerializedName("chatRoom")
@Expose
private ChatRoom chatRoom;
@SerializedName("created_at")
@Expose
private Map<String,String> created_at;
}
And my code to add new message :
String idM = databaseReference.push().getKey();
Message m = new Message(idM, message, sender, receiver, chatRoom, ServerValue.TIMESSTAMP);
databaseReference.child(idM).setValue(m);
Now I would like to set a default value to created_at like MySql :
Any idea?