{"record":{"id":"0d5cb955b46feea6","repo":"XINCGer/Unity3DTraining","slug":"haven-t-worked-out-what-to-do-for-null-yet","errorCode":null,"errorMessage":"Haven't worked out what to do for null yet","messagePattern":"Haven't worked out what to do for null yet","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":363,"sourceCode":"\n            switch (token.Type)\n            {\n                case JsonToken.TokenType.True:\n                case JsonToken.TokenType.False:\n                    if (fieldType == FieldType.Bool)\n                    {\n                        return token.Type == JsonToken.TokenType.True;\n                    }\n                    // Fall through to \"we don't support this type for this case\"; could duplicate the behaviour of the default\n                    // case instead, but this way we'd only need to change one place.\n                    goto default;\n                case JsonToken.TokenType.StringValue:\n                    return ParseSingleStringValue(field, token.StringValue);\n                // Note: not passing the number value itself here, as we may end up storing the string value in the token too.\n                case JsonToken.TokenType.Number:\n                    return ParseSingleNumberValue(field, token);\n                case JsonToken.TokenType.Null:\n                    throw new NotImplementedException(\"Haven't worked out what to do for null yet\");\n                default:\n                    throw new InvalidProtocolBufferException(\"Unsupported JSON token type \" + token.Type + \" for field type \" + fieldType);\n            }\n        }\n\n        /// <summary>\n        /// Parses <paramref name=\"json\"/> into a new message.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of message to create.</typeparam>\n        /// <param name=\"json\">The JSON to parse.</param>\n        /// <exception cref=\"InvalidJsonException\">The JSON does not comply with RFC 7159</exception>\n        /// <exception cref=\"InvalidProtocolBufferException\">The JSON does not represent a Protocol Buffers message correctly</exception>\n        public T Parse<T>(string json) where T : IMessage, new()\n        {\n            ProtoPreconditions.CheckNotNull(json, \"json\");\n            return Parse<T>(new StringReader(json));\n        }\n","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L345-L381","documentation":"ParseSingleValue handles string, number, and other concrete JSON tokens, but the JSON null token for a single (non-repeated, non-Any) field value is not implemented in this Google.Protobuf version, so it throws a NotImplementedException. This is an explicit feature gap rather than an input-validation failure.","triggerScenarios":"Calling JsonParser.Parse with JSON that assigns null to a single field, e.g. {\"optionalString\": null} or {\"myMessageField\": null}, reaching the Null case of the token switch.","commonSituations":"Backend/frontend JSON where null signals 'no value' (per canonical protobuf JSON spec, null should mean 'use default' but older parser versions didn't implement it); serializers that always emit keys with null values; version mismatch between the spec you read and the Google.Protobuf version in use.","solutions":["Preprocess the JSON to strip properties whose value is null before calling Parse (remove keys rather than emitting null).","Omit the field entirely — in proto3, an absent field equals the default value.","Upgrade Google.Protobuf: newer versions implement the canonical null-as-default behavior for some field kinds; verify against your version's release notes.","Catch NotImplementedException around Parse as a stopgap and log it as a payload-shape issue."],"exampleFix":"// before\n{\"userName\": null, \"userId\": 5}\n\n// after: omit the null field\n{\"userId\": 5}","handlingStrategy":"validation","validationCode":"// Remove keys whose value is null before parsing (null means 'use default' in proto3)\nfunction stripNulls(obj) {\n  if (Array.isArray(obj)) return obj.map(stripNulls);\n  if (obj && typeof obj === 'object') {\n    return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== null).map(([k, v]) => [k, stripNulls(v)]));\n  }\n  return obj;\n}","typeGuard":null,"tryCatchPattern":"try { var msg = JsonParser.Default.Parse<T>(json); }\ncatch (NotImplementedException) { /* payload contains null for a single field: strip nulls and retry, or upgrade library */ }","preventionTips":["Configure serializers to omit-null (not emit-null) when producing protobuf JSON","Omit fields rather than sending null; proto3 defaults apply on absence","Keep Google.Protobuf current — null handling per canonical spec was improved in later versions"],"tags":["protobuf","json-parsing","not-implemented","null-value"],"backgroundTag":"method-not-implemented","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"}