My json response is:
{
"categories": [
{
"categoryName": "Events",
"entityId": "QwN9goUaw6",
.....
}
],
"entityId": "T1nnwwpjOM"
}
My initial plan was to follow how Google did it in their GithubSampleBrowser, except they change from a List Integer to a List String using StringUtil methods, so I decided to change tactic and try and follow what some others have said in here to convert it to a String and back to an ArrayList.
I thought I had the right query that I wanted to eventually do i.e.
@Query("SELECT * FROM category_table WHERE entityId in (:entityId) ORDER BY sortIndex ASC")
public abstract LiveData<List<Category>> loadById(List<String> entityId);
My models are currently looking like:
CategorySearchResult
@NonNull
@PrimaryKey
private String entityId;
@Nullable
private String query;
public List<Category> categories;
private String lastUpdated;
Category
@NonNull
@PrimaryKey(autoGenerate = true)
private int id;
private Integer sortIndex;
private String storyboardId;
@NonNull
private String entityId;
private String categoryName;
private String menuId;
My attempt at the convertors:
@TypeConverter
public static List<Category> fromStringToCategory(String value) {
if (value != null) {
Gson gson = new Gson();
Type type = new TypeToken<List<Category>>() {
}.getType();
List<Category> categoryList = gson.fromJson(value,type);
return categoryList;
}
return null;
}
@TypeConverter
public static String fromCategoryToString(List<Category> categories) {
if (categories != null) {
Gson gson = new Gson();
Type type = new TypeToken<List<Category>>() {
}.getType();
String json = gson.toJson(categories, type);
return json;
}
return null;
}
What i thought might be easier is to generate a list of entityIds of category part of categorySearchResult and build a @Relationship between them. I've looked at the android documentation on the user and pets but can't properly relate it to my data so any advice would be greatly appreciated.