Skip to content

NullPointerException decoding PlannerChecklistItem #160

@klehmann

Description

@klehmann

We are trying to read MS Planner plans details and check list items via graph API and get a NullPointerException.

Expected behavior

PlannerChecklistItem can be decoded properly.

Actual behavior

Code throws NullPointerException.

Steps to reproduce the behavior

Create an MS Planner plan and add a task with a checklist item.

Use getGroups to read all groups:

	public static List<Group> getGroups(IGraphServiceClient graphAPI) {
		List<Group> allGroups = new ArrayList<>();
		
		IGroupCollectionRequest groupsReq = graphAPI.groups().buildRequest();
		IGroupCollectionPage currGroupPage;
		do {
			currGroupPage = groupsReq.get();
			
			List<Group> groupsInPage = currGroupPage.getCurrentPage();
			allGroups.addAll(groupsInPage);
			
			IGroupCollectionRequestBuilder nextPageReq = currGroupPage.getNextPage();
			if (nextPageReq==null) {
				break;
			}
			else {
				groupsReq = nextPageReq.buildRequest();
			}
		}
		while (true);
		
		return allGroups;
	}

Find the group corresponding to the plan and use getPlansForGroup to read the plan:

	public static List<PlannerPlan> getPlansForGroup(IGraphServiceClient graphAPI, Group group) {
		List<PlannerPlan> allPlans = new ArrayList<>();
		
		IPlannerPlanCollectionRequest plansReq = graphAPI.groups(group.id).planner().plans().buildRequest();
		IPlannerPlanCollectionPage currPlanPage;
		do {
			currPlanPage = plansReq.get();
			List<PlannerPlan> plansForPage = currPlanPage.getCurrentPage();
			
			for (PlannerPlan currPlan : plansForPage) {
				allPlans.add(currPlan);
			}
		
			IPlannerPlanCollectionRequestBuilder nextPageReq = currPlanPage.getNextPage();
			if (nextPageReq==null) {
				break;
			}
			else {
				plansReq = nextPageReq.buildRequest();
			}
		}
		while (true);
		
		return allPlans;
	}

For the returned plan, call getTasksForPlan to get all the tasks:

	public static List<PlannerTask> getTasksForPlan(IGraphServiceClient graphAPI, PlannerPlan plan) {
		List<PlannerTask> allTasks = new ArrayList<>();
		
		IPlannerTaskCollectionPage tasksPage = graphAPI.planner().plans(plan.id).tasks().buildRequest().get();
		do {
			List<PlannerTask> tasksInPage = tasksPage.getCurrentPage();
			allTasks.addAll(tasksInPage);
			
			IPlannerTaskCollectionRequestBuilder taskReqBuilder = tasksPage.getNextPage();
			if (taskReqBuilder==null) {
				break;
			}
			else {
				tasksPage = taskReqBuilder.buildRequest().get();
			}
		}
		while (true);
		
		return allTasks;
	}

Now try to read the task details:

	public static PlannerTaskDetails getTaskDetails(IGraphServiceClient graphAPI, PlannerTask task) {
		PlannerTaskDetails details = graphAPI.planner().tasks(task.id).details().buildRequest().get();
		return details;
	}

This returns JSON data looks like this:

{
	"references": {},
	"@odata.etag": "W/\"JzEtVGFza0RldGFpbHMgQEBAQEBAQEBAQEBAQEBAUCc=\"",
	"description": null,
	"checklist": {
		"42660": {
			"lastModifiedDateTime": "2018-10-28T14:29:37.7423391Z",
			"@odata.type": "#microsoft.graph.plannerChecklistItem",
			"orderHint": "8586608699726429822PK",
			"lastModifiedBy": {
				"user": {
					"displayName": null,
					"id": "f3a1dfe8-f2ef-4870-9642-413d468c571c"
				}
			},
			"title": "Ein Checklisteneintrag",
			"isChecked": false
		}
	},
	"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#planner/tasks('C6iIn6oJcEGcLX5XAiKeCZcAOv30')/details/$entity",
	"previewType": "automatic",
	"id": "C6iIn6oJcEGcLX5XAiKeCZcAOv30"
}

Deserialization to PlannerTaskDetails fails, because the JSON structure does not match the fields in PlannerChecklistItems.

Caused by: java.lang.NullPointerException
	at com.microsoft.graph.serializer.DefaultSerializer.setChildAdditionalData(DefaultSerializer.java:147)
	at com.microsoft.graph.serializer.DefaultSerializer.setChildAdditionalData(DefaultSerializer.java:138)
	at com.microsoft.graph.serializer.DefaultSerializer.deserializeObject(DefaultSerializer.java:103)

The reason is that the deserializer tried to read a value for public com.microsoft.graph.models.extensions.IdentitySet com.microsoft.graph.models.generated.BasePlannerChecklistItem.lastModifiedBy in this rawJson value (where only key "42660" exists):

{"42660":{"lastModifiedDateTime":"2018-10-28T14:29:37.7423391Z","@odata.type":"#microsoft.graph.plannerChecklistItem","orderHint":"8586608699726429822PK","lastModifiedBy":{"user":{"displayName":"","id":"f3a1dfe8-f2ef-4870-9642-413d468c571c"}},"title":"Ein Checklisteneintrag","isChecked":false}}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions