I am using Room to store data for my entity objects. Room requires that all fields be publicly accessible(with getters/setters). I also use this object as my Model in the MVVM pattern. Since the object is used for purposes other then data storage/persistence, I would like to encapsulate the fields of my entity objects(private fields). However, I have to expose public getters/setters for my method(or declare it as public), which breaks encapsulation in my project
The only solution I found is creating a separate object specially for Room as an Entity object, then converting my model to that object during data persistence. Is there a better solution to this? Can I make the public accessors to my fields only accessible by Room and not other classes?
Answers in Java or Kotlin are ok.
If you need more information(e.g. the code for the Entity class), please feel free to leave a comment.
Thanks.