+
Skip to content

Cast error at Repository.fromJson() #384

@Whiterzi

Description

@Whiterzi

The error occurs in version 9.12+:

This happens when using the webhook API and receiving a POST request from a GitHub webhook.

Cause: type 'String' is not a subtype of type 'Map<String, dynamic>' in type cast
#0      _$RepositoryFromJson (package:github/src/common/model/repos.g.dart:129:48)
#1      new Repository.fromJson (package:github/src/common/model/repos.dart:454:7)

The problematic code is here:

organization: json['organization'] == null
? null
: User.fromJson(json['organization'] as Map<String, dynamic>),

The data structure looks like this:

{
  "repository": {
    "id": 677211832,
    "node_id": "R_kgDOKF1uuA",
    "name": "orgREPO",
    "full_name": "whiterOrg/orgREPO",
    "private": true,
    "owner": {
      "name": "whiterOrg",
      "email": null
    },
    ...
    "html_url": "https://github.com/whiterOrg/orgREPO",
    "description": null,
    "fork": false,
    "master_branch": "main",
    "organization": "whiterOrg"
  }
}

The issue is that the field organization is a string in this payload, but the code attempts to cast it to a JSON object of type User.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载