-1

I need to type converter for calendar type to add room database.

error:

Cannot figure out how to save this field into database. You can consider adding a type converter for it.

Ömer Erden
  • 7,680
  • 5
  • 36
  • 45
  • Possible duplicate of [Room Using Date field](https://stackoverflow.com/questions/50313525/room-using-date-field) – Nabster May 16 '19 at 23:54

1 Answers1

0

While using Room DB for complex data you should write custom type converters. Please find an example for a Date converter (This will convert date to a Long value and back):

public class DateTypeConverter {

    @TypeConverter
    public static Date toDate(Long value) {
        return value == null ? null : new Date(value);
    }

    @TypeConverter
    public static Long toLong(Date value) {
        return value == null ? null : value.getTime();
    }
}

Also, you can refer to this answer.

Nabster
  • 1,187
  • 2
  • 10
  • 27