{"record":{"id":"24e31dcb8b47488e","repo":"SeleniumHQ/selenium","slug":"name-expected-an-object-on-the-wire-got-json-24e31d","errorCode":null,"errorMessage":"#{name} expected an object on the wire, got #{json_payload.inspect}","messagePattern":"#(.+?) expected an object on the wire, got #(.+?)","errorType":"exception","errorClass":"Error::SerializationError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/bidi/serialization/union.rb","lineNumber":63,"sourceCode":"            def fallback(path) = @fallback = path\n\n            # Declared (via the schema's `objectOnly` signal) on a union whose every arm is an\n            # object, so a non-Hash payload is a schema violation rather than a scalar arm.\n            def object_only = @object_only = true\n\n            # Declared (via the schema's `scalarValues` signal) on a non-object_only union whose\n            # bare-scalar arms are a fixed set of literals (input.Origin's \"viewport\" / \"pointer\").\n            # An outbound scalar outside that set matches no arm, so it is a caller error.\n            def scalar_values(*values) = @scalar_values = values\n\n            # A non-Hash payload is a bare scalar arm (e.g. input.Origin's \"viewport\") with no\n            # object to dispatch on, so it is returned unchanged — unless every arm is an object\n            # (object_only), where a non-Hash cannot match any variant and is a wire error.\n            def from_json(json_payload)\n              unless json_payload.is_a?(::Hash)\n                return json_payload unless @object_only\n\n                raise Error::SerializationError, \"#{name} expected an object on the wire, got #{json_payload.inspect}\"\n              end\n\n              variant = select(json_payload)\n              unless variant\n                raise Error::SerializationError,\n                      \"#{name} received a variant not in this Selenium's BiDi schema: #{json_payload.inspect}\"\n              end\n              Protocol.const_get(variant).from_json(json_payload)\n            end\n\n            # Outbound mirror of from_json: build the variant the command's kwargs describe\n            # so its typed as_json drives null-vs-absent per field (a flat hash through\n            # Transport cannot). Dispatch keys are wire names equal to their ruby kwarg\n            # (asserted at generation), so they match the kwargs by symbol. A mismatch here\n            # is a caller error (unlike an unknown inbound value), so it fails loudly.\n            def build(**kwargs)\n              variant = outbound_variant(kwargs) ||\n                        raise(::ArgumentError, \"no #{name} variant matches #{kwargs.inspect}\")","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/bidi/serialization/union.rb#L45-L81","documentation":"A BiDi Union type with every arm being an object (object_only) cannot match a bare scalar payload. from_json returns bare scalars unchanged for normal unions, but for object_only unions a non-Hash payload raises Error::SerializationError because no variant could match.","triggerScenarios":"Inbound BiDi payload at an object_only union field that is a non-Hash value (string, number, array, null-ish) — no object arm exists to dispatch to.","commonSituations":"Browser sends a bare scalar where the schema says every variant is an object, schema/client skew, non-conformant BiDi response.","solutions":["Inspect the raw payload to confirm a non-object arrived at an object-only union.","Verify the union is object_only in the current Selenium schema and the browser agrees.","Align Selenium and browser/driver versions.","Report the divergence with the payload."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def bidi_object?(payload)\n  payload.is_a?(::Hash)\nend","typeGuard":"def object_only_union_ok?(payload)\n  payload.is_a?(::Hash)\nend","tryCatchPattern":"begin\n  value = SomeUnion.from_json(payload)\nrescue Selenium::WebDriver::Error::SerializationError => e\n  raise unless e.message =~ /expected an object on the wire/\n  warn \"object-only union got scalar: #{e.message}\"\nend","preventionTips":["Confirm the union is object_only in the current schema before expecting scalar handling.","Log raw payloads to detect when a bare scalar arrives at an object-only union.","Pin compatible Selenium/browser versions to avoid schema drift."],"tags":["bidi","serialization","union","schema","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}