So I have a simple notes app, it has a noteModel class which extends RealmObject. I added a boolean value "pinned" to it but when I set this value to true it stops returning any of the data saved to it. The title starts returning null in the adapter and I can't use it but when I set "pinned" back to false everything goes back to normal.
Here is the Model class
public class NoteModel extends RealmObject {
#PrimaryKey
private int noteID;
private String note;
private String title;
private long timeStamp;
private boolean archived;
private boolean pinned;
public NoteModel() {
}
public boolean isPinned() {
return pinned;
}
public void setPinned(boolean pinned) {
this.pinned = pinned;
}
public int getNoteID() {
return noteID;
}
public void setNoteID(int noteID) {
this.noteID = noteID;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public long getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
}
public boolean isArchived() {
return archived;
}
public void setArchived(boolean archived) {
this.archived = archived;
}
}
Here is the adapter code:
switch (which) {
case 0:
if (noteModel.isPinned()) {
realm.beginTransaction();
noteModel.setPinned(false);
realm.commitTransaction();
Prevalent.allNotes.add(noteModel);
Prevalent.pinnedNotes.remove(pos);
} else {
realm.beginTransaction();
noteModel.setPinned(true);
realm.commitTransaction();
Prevalent.pinnedNotes.add(noteModel);
Prevalent.allNotes.remove(index);
}
notifyItemRemoved(index);
NotesFragment.pinNote();
break;
}
When it looses the data it just starts returning null for every get request apart from pinned
Related
I have a SearchView in my application that searches through notes in my RecyclerView (I am using Room Database to store the notes).
But after using the SearchView my other functions no longer work unless I restart the application.
These are the functions that no longer work after using the SearchView such as Adding note, Editing existing note, Deleting note and Pinning/Unpinning note.
This code is inside onCreate fucntion of MainActivity:
searchView_home = findViewById(R.id.searchView_home);
searchView_home.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
filter(newText);
return true;
}
});
This code is outside of onCreate function of MainActivity:
private void filter(String newText) {
List<Notes> filteredList = new ArrayList<>();
for (Notes singleNote: notes){
if (singleNote.getTitle().toLowerCase().contains(newText.toLowerCase())
|| singleNote.getNotes().toLowerCase().contains(newText.toLowerCase())){
filteredList.add(singleNote);
}
}
notesListAdapter.filterList(filteredList);
}
This code is inside onBindViewHolder of my NotesListAdapter class:
public void filterList(List<Notes> filteredList){
list = filteredList;
notifyDataSetChanged();
}
And this is the Notes model class itself:
#Entity(tableName = "notes")
public class Notes implements Serializable {
#PrimaryKey(autoGenerate = true)
int ID = 0;
#ColumnInfo(name = "title")
String title ="";
#ColumnInfo(name = "notes")
String notes = "";
#ColumnInfo(name = "date")
String date = "";
#ColumnInfo(name = "pinned")
boolean pinned = false;
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public boolean isPinned() {
return pinned;
}
public void setPinned(boolean pinned) {
this.pinned = pinned;
}
}
My Data Structure
My object has multiple ArrayLists and primitives.
On retrieving, I get this error Expected a List while deserializing, but got a class java.util.HashMap .
I understand I'm getting this error because that is how Firebase stores it.
I just have never worked with these many fields.
My question is can I convert it to my object directly?
malhobayyeb pointed this here https://stackoverflow.com/a/35979715/9860553 which seems pretty close to my case, but the answer he suggested is not working
I'm attaching my Objects structure too.
Though I think the code is not needed.
The issue is simply "in firebase, How to handle data if the list is inside another object "
package com.example.desktop.digitlbc.Model;
import java.util.ArrayList;
public class BusinessData {
private String
tvbAbout,
tvbProduct,tvbNews,tvbTrends,tvbOffers,
tvbEvents,
tvbCarrers;
private ArrayList<ImageData> idAlImageDataGallery;
private ArrayList<ImageData> idAlImageDataDocGallery;
private ArrayList<ImageData> idAlImageDataPersGallery;
private ArrayList<ImageData> idAlImageDataBizGallery;
private ArrayList<ImageData> idAlProduct;
private ArrayList<ImageData> idAlNews;
private ArrayList<ImageData> idAlTrends;
private ArrayList<ImageData> idAlOffers;
private String id;
private long timestamp;
private ArrayList<Product> product;
public BusinessData() {
}
public BusinessData(String tvbAbout, String tvbProduct, String tvbNews, String tvbTrends, String tvbOffers, String tvbEvents, String tvbCarrers, ArrayList<ImageData> idAlImageDataGallery, ArrayList<ImageData> idAlImageDataDocGallery, ArrayList<ImageData> idAlImageDataPersGallery, ArrayList<ImageData> idAlImageDataBizGallery, ArrayList<ImageData> idAlProduct, ArrayList<ImageData> idAlNews, ArrayList<ImageData> idAlTrends, ArrayList<ImageData> idAlOffers, String id, long timestamp, ArrayList<Product> product) {
this.tvbAbout = tvbAbout;
this.tvbProduct = tvbProduct;
this.tvbNews = tvbNews;
this.tvbTrends = tvbTrends;
this.tvbOffers = tvbOffers;
this.tvbEvents = tvbEvents;
this.tvbCarrers = tvbCarrers;
this.idAlImageDataGallery = idAlImageDataGallery;
this.idAlImageDataDocGallery = idAlImageDataDocGallery;
this.idAlImageDataPersGallery = idAlImageDataPersGallery;
this.idAlImageDataBizGallery = idAlImageDataBizGallery;
this.idAlProduct = idAlProduct;
this.idAlNews = idAlNews;
this.idAlTrends = idAlTrends;
this.idAlOffers = idAlOffers;
this.id = id;
this.timestamp = timestamp;
this.product = product;
}
public ArrayList<Product> getProduct() {
return product;
}
public void setProduct(ArrayList<Product> product) {
this.product = product;
}
public String getTvbAbout() {
return tvbAbout;
}
public void setTvbAbout(String tvbAbout) {
this.tvbAbout = tvbAbout;
}
public String getTvbProduct() {
return tvbProduct;
}
public void setTvbProduct(String tvbProduct) {
this.tvbProduct = tvbProduct;
}
public String getTvbNews() {
return tvbNews;
}
public void setTvbNews(String tvbNews) {
this.tvbNews = tvbNews;
}
public String getTvbTrends() {
return tvbTrends;
}
public void setTvbTrends(String tvbTrends) {
this.tvbTrends = tvbTrends;
}
public String getTvbOffers() {
return tvbOffers;
}
public void setTvbOffers(String tvbOffers) {
this.tvbOffers = tvbOffers;
}
public String getTvbEvents() {
return tvbEvents;
}
public void setTvbEvents(String tvbEvents) {
this.tvbEvents = tvbEvents;
}
public String getTvbCarrers() {
return tvbCarrers;
}
public void setTvbCarrers(String tvbCarrers) {
this.tvbCarrers = tvbCarrers;
}
public ArrayList<ImageData> getIdAlImageDataGallery() {
return idAlImageDataGallery;
}
public void setIdAlImageDataGallery(ArrayList<ImageData> idAlImageDataGallery) {
this.idAlImageDataGallery = idAlImageDataGallery;
}
public ArrayList<ImageData> getIdAlImageDataDocGallery() {
return idAlImageDataDocGallery;
}
public void setIdAlImageDataDocGallery(ArrayList<ImageData> idAlImageDataDocGallery) {
this.idAlImageDataDocGallery = idAlImageDataDocGallery;
}
public ArrayList<ImageData> getIdAlImageDataPersGallery() {
return idAlImageDataPersGallery;
}
public void setIdAlImageDataPersGallery(ArrayList<ImageData> idAlImageDataPersGallery) {
this.idAlImageDataPersGallery = idAlImageDataPersGallery;
}
public ArrayList<ImageData> getIdAlImageDataBizGallery() {
return idAlImageDataBizGallery;
}
public void setIdAlImageDataBizGallery(ArrayList<ImageData> idAlImageDataBizGallery) {
this.idAlImageDataBizGallery = idAlImageDataBizGallery;
}
public ArrayList<ImageData> getIdAlProduct() {
return idAlProduct;
}
public void setIdAlProduct(ArrayList<ImageData> idAlProduct) {
this.idAlProduct = idAlProduct;
}
public ArrayList<ImageData> getIdAlNews() {
return idAlNews;
}
public void setIdAlNews(ArrayList<ImageData> idAlNews) {
this.idAlNews = idAlNews;
}
public ArrayList<ImageData> getIdAlTrends() {
return idAlTrends;
}
public void setIdAlTrends(ArrayList<ImageData> idAlTrends) {
this.idAlTrends = idAlTrends;
}
public ArrayList<ImageData> getIdAlOffers() {
return idAlOffers;
}
public void setIdAlOffers(ArrayList<ImageData> idAlOffers) {
this.idAlOffers = idAlOffers;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}
Edit 1
The code is changed now. I've achieved what I wanted FOR NOW in a very caveman way, using the answer in the link above. But that leaves the code useless for future updates.
My original code was a straightforward valueEventListener. nothing special really. nothing at all.
businessData = dataSnapshot.getValue(BusinessData.class);
the refernece is pointing to the right location too
mRef = database.getReference(Common.id).child("bizData");
I want to use two class for database.
here is my source.
public class UserInfo extends RealmObject {
private String user_email;
private String nick_name;
private String expected_date;
private boolean initial_autho;
private int resultDay;
public int getResultDay() {
return resultDay;
}
public void setResultDay(int resultDay) {
this.resultDay = resultDay;
}
public String getUser_email() {
return user_email;
}
public void setUser_email(String user_email) {
this.user_email = user_email;
}
public String getNick_name() {
return nick_name;
}
public void setNick_name(String nick_name) {
this.nick_name = nick_name;
}
public String getExpected_date() {
return expected_date;
}
public void setExpected_date(String expected_date) {
this.expected_date = expected_date;
}
public boolean getInitial_autho() {
return initial_autho;
}
public void setInitial_autho(boolean initial_autho) {
this.initial_autho = initial_autho;
}
}
public class Calendar extends Realmobject {
private long millis;
private String note; // 노트
private String mail; // who
private int image; // image resource
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public long getTime() {
return millis;
}
public String getNote() {
return note;
}
public int getImage() {
return image;
}
public void setDate(long time) {
this.millis = time;
}
public void setNote(String note) {
this.note = note;
}
public void setImage(int image) {
this.image = image;
}
}
How do I use these things in Activity?
I don't know exactly and I much appreciate if you guys could tell about that more specifically as much as you can.
I am new to Android and I am developing app which has server side functionality. I am getting response in JSON format.
My response is shown as this image.
I know how to parse json using Volley but I don't know hot to parse using GSON. Previous code of my app was written by some one else. Now I have to complete this code. but I do not know how he getting data from JSON string.
I need JSON arrays in different activity. Array response:
image
Here is some snaps of my code.
Code for adapter for activity one
topicListAdapter = new TopicListAdapter(TopicActivity.this,
myCourseListMain. getCourseArrayList().get(Integer.parseInt(course_position)).
getTopicListMain().getTopicDetailsArrayList(), flag);
listAlltopics.setAdapter(topicListAdapter);
in which I got list of topics
here is code for second activity list adapter
lessionListAdapter = new LessionListAdapter(LessionActivity.this,
myCourseListMain. getCourseArrayList(). get(Integer.parseInt(course_position)).
getTopicListMain().getTopicDetailsArrayList().get(Integer.parseInt(topic_position)).getLessionArrayList(), flag);
by this code i got array of lession in second activity
Now I want sublession array in third activity but I don't know how to get it.
Here is what I tried
lessionListAdapter = new DummyAdapter(DummyTopicList.this,
myCourseListMain . getCourseArrayList(). get(Integer.parseInt(course_position)).
getTopicListMain() . getTopicDetailsArrayList() .get(Integer.parseInt(topic_position)).
getLessionLIstMain() .getLessionLIstDetailArrayList().get(Integer.parseInt(lession_position)). , flag);
listAlllessions.setAdapter(lessionListAdapter);
Here are some other classes which helpful to you for understand
public class MyCourseListMain {
#SerializedName("data")
private ArrayList<Course> courseArrayList;
public ArrayList<Course> getCourseArrayList() {
return courseArrayList;
}
public void setCourseArrayList(ArrayList<Course> courseArrayList) {
this.courseArrayList = courseArrayList;
}
}
class for course
public class Course {
#SerializedName("img")
private String img;
#SerializedName("title")
private String title;
#SerializedName("institute_id")
private String institute_id;
#SerializedName("institute_name")
private String institute_name;
#SerializedName("expired")
private String expired;
#SerializedName("status")
private String status;
#SerializedName("subscribe_box")
private String subscribe_box;
#SerializedName("expire_on")
private String expire_on;
#SerializedName("item_id")
private String item_id;
#SerializedName("rated")
private String rated;
private TopicListMain topicListMain;
public String getRated() {
return rated;
}
public void setRated(String rated) {
this.rated = rated;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getInstitute_id() {
return institute_id;
}
public void setInstitute_id(String institute_id) {
this.institute_id = institute_id;
}
public String getInstitute_name() {
return institute_name;
}
public void setInstitute_name(String institute_name) {
this.institute_name = institute_name;
}
public String getExpired() {
return expired;
}
public void setExpired(String expired) {
this.expired = expired;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getSubscribe_box() {
return subscribe_box;
}
public void setSubscribe_box(String subscribe_box) {
this.subscribe_box = subscribe_box;
}
public String getExpire_on() {
return expire_on;
}
public void setExpire_on(String expire_on) {
this.expire_on = expire_on;
}
public String getItem_id() {
return item_id;
}
public void setItem_id(String item_id) {
this.item_id = item_id;
}
public TopicListMain getTopicListMain() {
return topicListMain;
}
public void setTopicListMain(TopicListMain topicListMain) {
this.topicListMain = topicListMain; } }
class for topiclist_main
public class TopicListMain {
#SerializedName("data")
private ArrayList<TopicDetails> topicDetailsArrayList;
public ArrayList<TopicDetails> getTopicDetailsArrayList() {
return topicDetailsArrayList;
}
public void setTopicDetailsArrayList(ArrayList<TopicDetails> topicDetailsArrayList) {
this.topicDetailsArrayList = topicDetailsArrayList; }}
class for topic details
public class TopicDetails
{
#SerializedName("topic_id")
private String topic_id;
#SerializedName("title")
private String title;
#SerializedName("locked")
private String locked;
#SerializedName("lessons")
private ArrayList<Lession> lessionArrayList;
private LessionLIstMain lessionLIstMain;
public LessionLIstMain getLessionLIstMain() {
return lessionLIstMain;
}
public void setLessionLIstMain(LessionLIstMain lessionLIstMain) {
this.lessionLIstMain = lessionLIstMain;
}
public String getTopic_id() {
return topic_id;
}
public void setTopic_id(String topic_id) {
this.topic_id = topic_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLocked() {
return locked;
}
public void setLocked(String locked) {
this.locked = locked;
}
public ArrayList<Lession> getLessionArrayList() {
return lessionArrayList;
}
public void setLessionArrayList(ArrayList<Lession> lessionArrayList) {
this.lessionArrayList = lessionArrayList; }}
https://github.com/google/gson
Make your object have same construct with your data which you got.And
YourObject val = new Gson().fromJson(new String(YourString.getBytes("ISO-8859-1"),
"UTF-8"), YourObject.class);
finally i got my solution by below code.
lessionListAdapter = new DummyAdapter(DummyTopicList.this,
myCourseListMain . getCourseArrayList(). get(Integer.parseInt(course_position)).
getTopicListMain() . getTopicDetailsArrayList() .get(Integer.parseInt(topic_position)).
getLessionArrayList().get(Integer.parseInt((lession_position))).getLessionLIstDetailArrayList() , flag);
listAlllessions.setAdapter(lessionListAdapter);
i also made some few classes to handle json array.
public class SubLessionDetail {
#SerializedName("lesson_id")
private String lession_id;
#SerializedName("title")
private String title;
#SerializedName("locked")
private String locked;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLocked() {
return locked;
}
public void setLocked(String locked) {
this.locked = locked;
}
public String getLession_id() {
return lession_id;
}
public void setLession_id(String lession_id) {
this.lession_id = lession_id;
}
}
I have an object which I for now save using SharedPreferences like this:
public String getActiveTripString(Context con) {
return preferences.getString(ACTIVE_TRIP, "-1");
}
public void setActiveTripString(Context context, String string) {
setString(context, string, ACTIVE_TRIP);
}
public PSTrip getActiveTrip(Context context) {
String active = getActiveTripString(context);
PSTrip psTrip = null;
if (active.contentEquals("-1")) {
return null;
} else {
try{
psTrip = JsonUtil.jsonToObject(active, PSTrip.class);
}catch (Exception e){
Log.i("","getActiveTrip error is:" + e.getMessage());
}
return psTrip;
}
}
public void setActiveTrip(PSTrip psTrip, Context context) {
try{
setActiveTripString(context, JsonUtil.objectToJson(psTrip, PSTrip.class));
}catch (Exception e){
Log.i("","setActiveTrip error is:" + e.getMessage());
}
}
Where I have function as you can see, that create a json and then save it as a string in SharedPrefferences. But The object is BIG, and the more I add into it, the app start to be more laggy until it's unresponsive.
I also need to use this object in a lot of places, so I always need to call:
GetActiveTrip to get it, make my modifications, then SetActiveTrip to save it.
I'm looking for a more efficient way to save it. I tried with REALM, to save it in a database, but because my object is so big, and modified in a lot of places, I did not quite manage to make it work, Having to call Realm a lot just to add items in the database, in order to have managed database items, so I can add them in my object, and so on. Which also I think might be memory consuming. And It crashes a lot with realm exceptions.
Any other way I could do this? Is saving to a file more efficient than to Shared Preferences? As I saw in Android Monitor, analysing my traces, the GSON function that creates the JSON takes a lot of resources.
Any suggestions what I could use?
EDIT: My object:
public class PSTrip extends RealmObject {
private boolean valid;
private String type;
private String travel_mode;
#PrimaryKey
private String id;
private Owner_data owner_data;
private int distance;
private String name;
private double checkinLat;
private double checkinLng;
private double checkoutLng;
private double checkoutLat;
private String icon;
private String status;
private Destination destination;
private int checkout_time;
private int checkin_time;
private Route route;
private String owner;
private String vehicle;
private Flight flight;
#SerializedName("last_updated")
private int lastUpdated;
#SerializedName("steps")
private RealmList<TripStep> tripSteps;
private RealmList<Record> records;
#SerializedName("planned_route")
private Planned_Route plannedRoute;
private Group group;
private float emissions;
private Co2PerKm co2_per_km;
private int update_interval;
private boolean isRoaming = false;
public boolean getIsRoaming() {
return isRoaming;
}
public void setIsRoaming(boolean isRoaming) {
this.isRoaming = isRoaming;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public int getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(int lastUpdated) {
this.lastUpdated = lastUpdated;
}
public RealmList<TripStep> getTripSteps() {
return tripSteps;
}
public void setTripSteps(RealmList<TripStep> steps) {
this.tripSteps = steps;
}
public String getVehicle() {
return vehicle;
}
public void setVehicle(String vehicle) {
this.vehicle = vehicle;
}
public Flight getFlight() {
return flight;
}
public void setFlight(Flight flight) {
this.flight = flight;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTravel_mode() {
return travel_mode;
}
public void setTravel_mode(String travel_mode) {
this.travel_mode = travel_mode;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Owner_data getOwner_data() {
return owner_data;
}
public void setOwner_data(Owner_data owner_data) {
this.owner_data = owner_data;
}
public int getDistance() {
return distance;
}
public void setDistance(int distance) {
this.distance = distance;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Destination getDestination() {
return destination;
}
public void setDestination(Destination destination) {
this.destination = destination;
}
public int getCheckout_time() {
return checkout_time;
}
public void setCheckout_time(int checkout_time) {
this.checkout_time = checkout_time;
}
public int getCheckin_time() {
return checkin_time;
}
public void setCheckin_time(int checkin_time) {
this.checkin_time = checkin_time;
}
public Route getRoute() {
return route;
}
public void setRoute(Route route) {
this.route = route;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public PSTrip() {
}
public PSTrip(String id) {
this.id = id;
}
public double getCheckoutLng() {
return checkoutLng;
}
public void setCheckoutLng(double checkoutLng) {
this.checkoutLng = checkoutLng;
}
public double getCheckinLat() {
return checkinLat;
}
public void setCheckinLat(double checkinLat) {
this.checkinLat = checkinLat;
}
public double getCheckinLng() {
return checkinLng;
}
public void setCheckinLng(double checkinLng) {
this.checkinLng = checkinLng;
}
public double getCheckoutLat() {
return checkoutLat;
}
public void setCheckoutLat(double checkoutLat) {
this.checkoutLat = checkoutLat;
}
public boolean isRoaming() {
return isRoaming;
}
public void setRoaming(boolean isRoaming) {
this.isRoaming = isRoaming;
}
public Planned_Route getPlannedRoute() {
return plannedRoute;
}
public void setPlannedRoute(Planned_Route plannedRoute) {
this.plannedRoute = plannedRoute;
}
public boolean isValid() {
return valid;
}
public float getEmissions() {
return emissions;
}
public void setEmissions(float emissions) {
this.emissions = emissions;
}
public Co2PerKm getCo2_per_km() {
return co2_per_km;
}
public void setCo2_per_km(Co2PerKm co2_per_km) {
this.co2_per_km = co2_per_km;
}
public void setValid(boolean valid) {
this.valid = valid;
}
public int getUpdate_interval() {
return update_interval;
}
public void setUpdate_interval(int update_interval) {
this.update_interval = update_interval;
}
public RealmList<Record> getRecords() {
return records;
}
public void setRecords(RealmList<Record> records) {
this.records = records;
}
}
Where: Route, Destination are the google maps object, if you are familiar with them, you know what they include and their size;
TripStep = similar with the STEP object from google BUT, it includes 2 arrays:
private RealmList<StopInfo> filteredLocations = new RealmList<>();
private RealmList<StopInfo> rawLocations = new RealmList<>();
In which I have to add a new location every 5-6 seconds in the rawLocations.
Add a new location each time the rawlocation I get is farther than x metres from the last rawLocation I got.
Getting the Object from Preferences, deserialising, getting the latest TripStep and adding the new Location to the filteredLocations and rawLocations seems to take a log of memory. So This is what I think is the problem
After all, I chose to use Realm, instead of shared preferences, it's more efficient, and even if I still have some issues with the changes I make to my file, I'm getting to a stable version quickly.
It has it's downsides (some REALM objects are not serialised correctly by GSON, and you will need to use jackson, and also not being able to use functions inside your model, or that it supports just primitives is a big issue with it, but if you manage to go over this, it's worth it)
Would not suggest adding Realm database to a project that is already big