We currently have TaskSet implementing JsonSerializable, and that is used in CacheDecorator when we cache a TaskSet for a user.
However when we ship JSON for use in client-side code, we end up using a custom format in both Suggested Edits and ApiQueryGrowthTasks:
ApiQueryGrowthTasks:
'@phan-var TaskSet $tasks'; foreach ( $tasks as $i => $task ) { $title = Title::newFromLinkTarget( $task->getTitle() ); $extraData = [ 'tasktype' => $task->getTaskType()->getId(), 'difficulty' => $task->getTaskType()->getDifficulty(), 'order' => $i, 'qualityGateIds' => $task->getTaskType()->getQualityGateIds(), 'qualityGateConfig' => $tasks->getQualityGateConfig(), 'token' => $task->getToken() ]; // snip
SuggestedEdits.php:
$data['task-preview'] = [ 'tasktype' => $task->getTaskType()->getId(), 'difficulty' => $task->getTaskType()->getDifficulty(), 'qualityGateIds' => $task->getTaskType()->getQualityGateIds(), 'qualityGateConfig' => $tasks->getQualityGateConfig(), 'title' => $title->getPrefixedText(), 'topics' => $task->getTopicScores(), // The front-end code for constructing SuggestedEditCardWidget checks // to see if pageId is set in order to construct a tracking URL. 'pageId' => $title->getArticleID(), 'token' => $task->getToken() ];
Ideally we could have a common method for outputting JSON that would be used for the client. I don't think we want the existing JSON serialization for TaskSet because that contains a lot more data than the client actually needs, so two possibilites are 1) a shared static method for converting a TaskSet into a light-weight client-side array, or 2) a ClientSideTaskSet that impelments JsonSerilazable in a way that discards unnecessary data and returns the existing structured used in ApiQueryGrowthTasks.