Android Room - error: Cannot figure out how to save this field into database

前端 未结 3 1593
清酒与你
清酒与你 2020-12-16 19:22

Detailed log

error: Cannot figure out how to save this field into database. You can 
consider adding a type converter for it.
private final java.util.Date m         


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 19:57

    All above answers is for list of strings.But below helps you to find converter for list of your objects.

    Just in place of "YourClassName" ,add your Object class.

     @TypeConverter
            public String fromValuesToList(ArrayList<**YourClassName**> value) {
                if (value== null) {
                    return (null);
                }
                Gson gson = new Gson();
                Type type = new TypeToken>() {}.getType();
                return gson.toJson(value, type);
            }
        
            @TypeConverter
            public ArrayList<**YourClassName**> toOptionValuesList(String value) {
                if (value== null) {
                    return (null);
                }
                Gson gson = new Gson();
                Type type = new TypeToken>() {
                }.getType();
                return gson.fromJson(value, type);
            }
    

提交回复
热议问题