Search code examples
androiddatabaserealmrealm-java

How to save objects of external libraries in realm?


I know I need to extend RealmObject on all the objects that I have in realm, in order to create the database, but I use google maps and so I have a list of LatLng's in a object that I need to store in Realm. The LatLng is a google maps class, so I do not have access to the .java file, so I cannot create a copy of that object that extends RealmObject. Has anybody found a workaround this issue, is it possible?


Solution

  • Create your own class (e.g. MyLatLng) which mimics LatLng structure. Next create static method inside your MyLatLng class which converts MyLatLng object to LatLng object and vice versa. It have to be static because only setters and getters are allowed methods in RealmObject classes.