Android Room: Storing a List of Objects
2 min readNov 7, 2017
How to store a list of objects using Android Room.
I have been extending the Github browser sample put out by the Android team, and while it is great for the most part, when I tried to add a List<SomeObject> to an Entity, I encountered a stack trace which was hard to parse:
As it turns out, the solution is there, but rather hidden:
Adding a type converter was easy, I just needed a method that could turn the list of objects into a string, and a method that could do the reverse. I used gson for this.
I then added an annotation to the field in the Entity:
@TypeConverters(GithubTypeConverters.class)
public final List<SomeObject> someObjects;
Now lists of objects can be stored in the Room database. Check out the documentation: