{
  "id": "go/json-marshal-infinite-recursion",
  "signature": "json: invalid recursive type: type MyStruct has recursive JSON method",
  "signature_zh": "json：无效的递归类型：类型 MyStruct 具有递归 JSON 方法",
  "regex": "json: invalid recursive type:.*has recursive JSON method",
  "domain": "go",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "A custom MarshalJSON or UnmarshalJSON method on a type calls json.Marshal or json.Unmarshal on itself, causing infinite recursion.",
  "root_cause_type": "generic",
  "root_cause_zh": "类型上的自定义 MarshalJSON 或 UnmarshalJSON 方法对自身调用 json.Marshal 或 json.Unmarshal，导致无限递归。",
  "versions": [
    {
      "version": "Go 1.15",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.16",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.23",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Both functions call the same MarshalJSON method; recursion persists.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses custom serialization behavior; data may be serialized incorrectly.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "json package detects recursion before runtime depth limit; counter doesn't prevent detection.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Define an alias type (type MyStructAlias MyStruct) and marshal the alias instead of the original type",
      "success_rate": 0.95,
      "how": "Define an alias type (type MyStructAlias MyStruct) and marshal the alias instead of the original type",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a raw byte slice or map[string]interface{} for manual marshaling without calling json.Marshal on self",
      "success_rate": 0.9,
      "how": "Use a raw byte slice or map[string]interface{} for manual marshaling without calling json.Marshal on self",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement MarshalJSON by calling json.Marshal on a temporary struct that mirrors the fields without the recursive method",
      "success_rate": 0.85,
      "how": "Implement MarshalJSON by calling json.Marshal on a temporary struct that mirrors the fields without the recursive method",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Define an alias type (type MyStructAlias MyStruct) and marshal the alias instead of the original type",
    "Use a raw byte slice or map[string]interface{} for manual marshaling without calling json.Marshal on self",
    "Implement MarshalJSON by calling json.Marshal on a temporary struct that mirrors the fields without the recursive method"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pkg.go.dev/encoding/json#Marshaler",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-07-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}