kstateome/canvas-api

DateTimeParseException when retrieving AssignmentOverrides

Opened this issue · 0 comments

A DateTimeParseException error is thrown whenever you attempt to retrieve assignment overrides for an assignment that actually has some overrides.

List<AssignmentOverride> overrides = reader.listAssignmentOverrides(courseId, assignmentId) ;

throws:

com.google.gson.JsonParseException: java.time.format.DateTimeParseException: Text '2024-08-20' could not be parsed at index 10
	at edu.ksu.canvas.impl.GsonResponseParser$6.deserialize(GsonResponseParser.java:79) ~[canvas-api-2.0.0.jar:na]
	at edu.ksu.canvas.impl.GsonResponseParser$6.deserialize(GsonResponseParser.java:67) ~[canvas-api-2.0.0.jar:na]
	at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:69) ~[gson-2.9.0.jar:na]
	at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:63) ~[gson-2.9.0.jar:na]
        ...

The cause is the all_day_date field, which is in the format "yyyy-MM-dd" (with no time or timezone data), and consequently cannot be parsed as a Date by gson.

Two possible fixes:

  1. Edit the getDefaultGsonParser in edu.ksu.canvas.impl.GsonResponseParser to have another fallback to handle these date formats.
  2. Turn the AssignmentOverride.allDayDate field into a String instead of a Date.

I would lean towards option 2, since it would be unwise to treat this as a date anyway given that it has no timezone info.

Happy to write a pull request, but will anyone action it? This is a great repository but it seems like it has been dead for a few years now?