I need to get json data from api and convert it to java object. I use Gson like this:
public void saveData(JsonObject data) {
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new DateDeserializer()).create();
Structure structure = gson.fromJson(data.get("structure").toString(), Structure.class);
//working with structure object
}
But sometimes api returns a very large json (about 50MB), which causes out of memory exception.
That's the Structure class:
@Parcel(value = Parcel.Serialization.BEAN, analyze = {Structure.class})
public class Structure extends RealmObject {
@SerializedName("id")
@PrimaryKey
@Expose
@Index
public int id;
@SerializedName("date")
@Expose
public String date;
@SerializedName("notes")
@Expose
@ParcelPropertyConverter(RealmListParcelConverter.class)
public RealmList<StructureNote> notes;
//other fileds
The main problem is in "notes" filed - it contains about 80% of all json file that I'm getting from api.
How can I convert such a large json to Java object? I've been thinking about splitting notes list to some parts and after that add it to each other, but I don't know if this is even possible.