{"record":{"id":"323e94a1ffee9b25","repo":"XINCGer/Unity3DTraining","slug":"invalid-string-for-bool-map-key","errorCode":null,"errorMessage":"Invalid string for bool map key: ","messagePattern":"Invalid string for bool map key: ","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":578,"sourceCode":"                throw new InvalidProtocolBufferException(\"Expected end-object token after @type/value for well-known type\");\n            }\n        }\n\n        #region Utility methods which don't depend on the state (or settings) of the parser.\n        private static object ParseMapKey(FieldDescriptor field, string keyText)\n        {\n            switch (field.FieldType)\n            {\n                case FieldType.Bool:\n                    if (keyText == \"true\")\n                    {\n                        return true;\n                    }\n                    if (keyText == \"false\")\n                    {\n                        return false;\n                    }\n                    throw new InvalidProtocolBufferException(\"Invalid string for bool map key: \" + keyText);\n                case FieldType.String:\n                    return keyText;\n                case FieldType.Int32:\n                case FieldType.SInt32:\n                case FieldType.SFixed32:\n                    return ParseNumericString<int>(keyText, int.Parse);\n                case FieldType.UInt32:\n                case FieldType.Fixed32:\n                    return ParseNumericString<uint>(keyText, uint.Parse);\n                case FieldType.Int64:\n                case FieldType.SInt64:\n                case FieldType.SFixed64:\n                    return ParseNumericString<long>(keyText, long.Parse);\n                case FieldType.UInt64:\n                case FieldType.Fixed64:\n                    return ParseNumericString<ulong>(keyText, ulong.Parse);\n                default:\n                    throw new InvalidProtocolBufferException(\"Invalid field type for map: \" + field.FieldType);","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L560-L596","documentation":"ParseMapKey converts JSON map keys (which are always strings) to the map's key field type. For bool keys, only the exact strings 'true' and 'false' are accepted per the protobuf JSON mapping; anything else throws this InvalidProtocolBufferException.","triggerScenarios":"Parsing JSON for a map<bool, ...> with keys like 'True', 'FALSE', '1', or '0' — protobuf JSON requires lowercase 'true'/'false' string keys.","commonSituations":"JSON generated by a non-conforming serializer using 'True'/'False' (PascalCase) or numeric '1'/'0' for boolean map keys; hand-written JSON.","solutions":["Change bool map keys to lowercase 'true'/'false' in the JSON.","If the producer cannot be fixed, change the map key type to string or int32 in the .proto and convert on both sides.","Pre-normalize keys (map 'True'->'true', '1'->'true') before passing JSON to the parser."],"exampleFix":"// before\n{\"myBoolMap\": {\"True\": 1, \"False\": 2}}\n// after\n{\"myBoolMap\": {\"true\": 1, \"false\": 2}}","handlingStrategy":"validation","validationCode":"// Normalize/validate bool map keys before parsing\nstring normalized = Regex.Replace(json,\n    '\"(True|False|TRUE|FALSE|1|0)\"\\\\s*:',\n    m => '\"' + (m.Groups[1].Value.Equals(\"True\", StringComparison.OrdinalIgnoreCase) || m.Groups[1].Value == \"1\" ? \"true\" : \"false\") + '\":');","typeGuard":null,"tryCatchPattern":"try\n{\n    var msg = parser.Parse<T>(json);\n}\ncatch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Invalid string for bool map key:\"))\n{\n    // re-run with normalized keys or reject payload\n}","preventionTips":["Emit bool map keys as exactly lowercase 'true'/'false' in JSON producers","Avoid serializers that PascalCase JSON keys","Prefer string or int map keys when interop with non-conforming producers is expected"],"tags":["protobuf","json-parsing","map-key","bool"],"backgroundTag":"invalid-argument-format","analyzedSha":"016f98412ea5e11756b286736f479b66ab6216d5","analyzedAt":"2026-09-12T01:08:58.711Z","contentChangedAt":"2026-09-12T01:08:58.711Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}