My TypeConverter is not working for converting GregorianCalendar to an sql Date type. An error is being thrown on the following code:
/** due date of item */
@TypeConverters({CalendarConverter.class})
private GregorianCalendar dueDate = null;
Error:(42, 31) error: Cannot figure out how to save this field into database. You can consider adding a type converter for it.
The TypeConverter code:
public class CalendarConverter {
@TypeConverter
public static GregorianCalendar fromDate(Date value){
if(value == null){
throw new NullPointerException("must not be null");
}
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(value);
return cal;
}
@TypeConverter
public static Date toDate(GregorianCalendar calendar){
if(calendar != null){
throw new NullPointerException("must not be null");
}
Calendar cal = calendar;
return new Date(cal.getTime().getTime());
}
}