TL; DR
How to migrate POJOs with ISO8601 string datetime fields to Google Firebase Database, allowing automatic deserialization with Google GSON?
Description
Given the follwing POJO written using Jackson annotations:
@JsonIgnoreExtraProperties(ignoreUnknown = true)
public class ChatMessage {
public String name;
public String message;
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
)
public Date createdAt;
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
)
public Date updatedAt;
@JsonIgnore
public String ignoreThisField;
}
According to Firebase Database migration for Android, this is how and ChatMessage
would look using only GSON:
public class ChatMessage {
public String name;
public String message;
public Date createdAt;
public Date updatedAt;
@Exclude
public String ignoreThisField;
}
I have already seeing solutions using custom deserializers, but it would require rewrite dozens of objects.