go
data_error
ai_generated
true
proto: (line 1:15): unknown field "userName"
ID: go/proto-json-unknown-field
80%Fix Rate
88%Confidence
0Evidence
2024-08-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| google.golang.org/protobuf v1.30+ | active | — | — | — |
Root Cause
protojson.Unmarshal encountered a JSON key that does not match any field in the message. By default protojson rejects unknown fields and is case-sensitive on the proto field names (camelCase or snake_case accepted).
generic中文
protojson.Unmarshal 遇到与消息中任何字段都不匹配的 JSON 键。默认情况下 protojson 拒绝未知字段,且对 proto 字段名大小写敏感(接受 camelCase 或 snake_case)。
Workarounds
-
90% success
opts := protojson.UnmarshalOptions{DiscardUnknown: true} err := opts.Unmarshal(data, msg) -
85% success
// user.proto string user_name = 1 [json_name = "userName"];
Dead Ends
Common approaches that don't work:
-
60% fail
Field renames change the wire contract and require regenerating all clients; it treats a symptom, not the schema mismatch.
-
85% fail
protojson returns an error and leaves the message partially populated or empty; downstream reads wrong data.