I am using Room for DB and have a table by the name of 'Products'. Products Entity class has field ArrayList'String' tags.
@Entity Class Products { some auto generate primary key; String name; ArrayList<String>tags;}
I want to search products by tag, so how to do it? Can we use 'tags' in where clause? I tried below but didn't work:
select name from Products where tags IN (:value)
List<String> getSearchedProducts(String value);
Using this type converter to save list.
public class StringListConverters {
private static Gson gson = new Gson();
@TypeConverter
public static ArrayList<String> fromString(String data) {
Type listType = new TypeToken<ArrayList<String>>() {}.getType();
return gson.fromJson(data, listType);
}
@TypeConverter
public static String fromArrayList(ArrayList<String> list) {
return gson.toJson(list);
}
}
For search by name it works but for search by tag it doesn't. More than syntax, error fix etc. here I am looking for approach to search Collections in Room DB.