go
type_error
ai_generated
true
json: unsupported type: chan int
ID: go/json-marshal-unsupported-type
80%Fix Rate
85%Confidence
0Evidence
2024-12-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
Root Cause
Attempting to marshal a Go type that is not supported by encoding/json, such as channels, functions, or complex numbers.
generic中文
尝试序列化 encoding/json 不支持的 Go 类型,如通道、函数或复数。
Workarounds
-
90% success
Use custom MarshalJSON method: func (c MyChan) MarshalJSON() ([]byte, error) { return json.Marshal("chan") } -
95% success
Define struct with exported fields only: type S struct { Data string `json:"data"` }
Dead Ends
Common approaches that don't work:
-
60% fail
Data loss; field missing.
-
80% fail
Channels can't be converted; type mismatch.