{"record":{"id":"a1254991a08ce907","repo":"XINCGer/Unity3DTraining","slug":"expected-end-object-token-after-type-value-for-we","errorCode":null,"errorMessage":"Expected end-object token after @type/value for well-known type","messagePattern":"Expected end-object token after @type/value for well-known type","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":560,"sourceCode":"        }\n\n        // Well-known types end up in a property called \"value\" in the JSON. As there's no longer a @type property\n        // in the given JSON token stream, we should *only* have tokens of start-object, name(\"value\"), the value\n        // itself, and then end-object.\n        private void MergeWellKnownTypeAnyBody(IMessage body, JsonTokenizer tokenizer)\n        {\n            var token = tokenizer.Next(); // Definitely start-object; checked in previous method\n            token = tokenizer.Next();\n            // TODO: What about an absent Int32Value, for example?\n            if (token.Type != JsonToken.TokenType.Name || token.StringValue != JsonFormatter.AnyWellKnownTypeValueField)\n            {\n                throw new InvalidProtocolBufferException(\"Expected '\" + JsonFormatter.AnyWellKnownTypeValueField + \"' property for well-known type Any body\");\n            }\n            Merge(body, tokenizer);\n            token = tokenizer.Next();\n            if (token.Type != JsonToken.TokenType.EndObject)\n            {\n                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);","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L542-L578","documentation":"After merging the 'value' property of an Any-wrapped well-known type, the parser requires the JSON object to terminate with an EndObject token. Extra/missing braces or trailing content inside the Any body cause this InvalidProtocolBufferException.","triggerScenarios":"Parsing Any JSON where the well-known-type body has a nested object mismatch — e.g. {'@type':..., 'value':{...}} missing a closing brace, or an extra property/object token left before the object ends.","commonSituations":"Malformed or truncated JSON produced by a buggy serializer; manual string concatenation building Any JSON; copy/paste errors in hand-written test fixtures.","solutions":["Validate the JSON is well-formed and the Any object closes correctly (pass it through a JSON validator first).","Fix braces so the Any body object ends right after the value property.","Check the producer's serializer output — regenerate with a spec-compliant protobuf JSON serializer."],"exampleFix":"// before\n{\"@type\":\"type.googleapis.com/google.protobuf.Struct\",\"value\":{\"a\":1}\n// after\n{\"@type\":\"type.googleapis.com/google.protobuf.Struct\",\"value\":{\"a\":1}}","handlingStrategy":"validation","validationCode":"// Ensure the payload is well-formed JSON before protobuf parsing\nJToken.Parse(json); // throws Newtonsoft.Json.JsonReaderException on malformed JSON","typeGuard":"static bool IsWellFormedJson(string json)\n{\n    try { JToken.Parse(json); return true; }\n    catch (JsonReaderException) { return false; }\n}","tryCatchPattern":"try\n{\n    var msg = parser.Parse<T>(json);\n}\ncatch (InvalidProtocolBufferException ex) when (ex.Message.Contains(\"Expected end-object token\"))\n{\n    // treat payload as corrupted; request retransmission or log for forensics\n}","preventionTips":["Validate JSON syntax before feeding it to the protobuf parser","Avoid manual string concatenation when building Any JSON","Round-trip test Any payloads between producer and consumer"],"tags":["protobuf","json-parsing","malformed-json"],"backgroundTag":"json-parse-error","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"}