{"record":{"id":"a3be01286c1e27d8","repo":"XINCGer/Unity3DTraining","slug":"unsupported-conversion-from-json-number-for-field","errorCode":null,"errorMessage":"Unsupported conversion from JSON number for field type ","messagePattern":"Unsupported conversion from JSON number for field type ","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":653,"sourceCode":"                            {\n                                if (double.IsPositiveInfinity(value))\n                                {\n                                    return float.PositiveInfinity;\n                                }\n                                if (double.IsNegativeInfinity(value))\n                                {\n                                    return float.NegativeInfinity;\n                                }\n                                throw new InvalidProtocolBufferException(\"Value out of range: \" + value);\n                            }\n                            return (float)value;\n                        case FieldType.Enum:\n                            CheckInteger(value);\n                            // Just return it as an int, and let the CLR convert it.\n                            // Note that we deliberately don't check that it's a known value.\n                            return (int)value;\n                        default:\n                            throw new InvalidProtocolBufferException(\"Unsupported conversion from JSON number for field type \" + field.FieldType);\n                    }\n                }\n                catch (OverflowException)\n                {\n                    throw new InvalidProtocolBufferException(\"Value out of range: \" + value);\n                }\n            }\n        }\n\n        private static void CheckInteger(double value)\n        {\n            if (double.IsInfinity(value) || double.IsNaN(value))\n            {\n                throw new InvalidProtocolBufferException(\"Value not an integer: \" + value);\n            }\n            if (value != Math.Floor(value))\n            {\n                throw new InvalidProtocolBufferException(\"Value not an integer: \" + value);","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L635-L671","documentation":"ParseSingleNumberValue only supports JSON numbers for numeric field types (int/uint/float/double/enum). If a field's FieldType is non-numeric (e.g. string, bytes, message), the switch reaches default and throws this InvalidProtocolBufferException.","triggerScenarios":"Parsing JSON where a JSON number is supplied for a field declared as a string, bytes, or message type — e.g. {\"name\": 123} for a string field, often from a schema mismatch between producer and consumer.","commonSituations":"API version drift where a field's type changed between schema versions; hand-written JSON assigning numbers to string fields; dynamic descriptors pointing at the wrong field.","solutions":["Fix the JSON so the field's JSON type matches its schema type (quote numbers for string fields).","Regenerate code so client descriptors match the producer's schema version.","If the producer legitimately changed the type, update the .proto and both sides together."],"exampleFix":"// before (string field 'name')\n{\"name\": 123}\n// after\n{\"name\": \"123\"}","handlingStrategy":"type-guard","validationCode":"// Verify JSON value types match field types before parsing\n// e.g. for a string field:\nvar token = JToken.Parse(json)[\"name\"];\nif (token != null && token.Type != JTokenType.String)\n    throw new FormatException($\"Field 'name' must be a JSON string, got {token.Type}\");","typeGuard":"static bool IsJsonStringForStringField(JToken token) => token == null || token.Type == JTokenType.String;","tryCatchPattern":"try\n{\n    var msg = parser.Parse<T>(json);\n}\ncatch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Unsupported conversion from JSON number\"))\n{\n    // log schema-mismatch details; align producer/consumer schema versions\n}","preventionTips":["Keep .proto files versioned and shared between producer and consumer","Add contract tests asserting JSON value types per field","Reject non-conforming payloads at the producer, not the consumer"],"tags":["protobuf","json-parsing","type-mismatch"],"backgroundTag":"type-mismatch","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"}