Десериализация subclass. Из Json в Java
Есть класс Message - предок и класс MessageHistory - наследник. Как десериализовать наследника ? Использую библиотеку - GSON.
public class Message {
@SerializedName("id")
private int id;
@SerializedName("date")
private long date;
@SerializedName("out")
private int out;
@SerializedName("user_id")
private int userId;
public Message(int id, long date, int userId, int out) {
this.id = id;
this.date = date;
this.userId = userId;
this.out = out;
}
}
public class MessageHistory extends Message {
@SerializedName("from_id")
private int fromId;
public MessageHistory(int id, long date, int userId, int out, int fromId) {
super(id, date, userId, out);
this.fromId = fromId;
}
}
Источник: Stack Overflow на русском