{"record":{"id":"b270593164a196ee","repo":"bblimke/webmock","slug":"can-t-convert-new-query-values-class-into-hash","errorCode":null,"errorMessage":"Can't convert #{new_query_values.class} into Hash.","messagePattern":"Can't convert #(.+?) into Hash\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/webmock/util/query_mapper.rb","lineNumber":185,"sourceCode":"          else\n            current_node[last_key] = value\n          end\n        end\n      end\n\n      ##\n      # Sets the query component for this URI from a Hash object.\n      # This method produces a query string using the :subscript notation.\n      # An empty Hash will result in a nil query.\n      #\n      # @param [Hash, #to_hash, Array] new_query_values The new query values.\n      def values_to_query(new_query_values, options = {})\n        options[:notation] ||= :subscript\n        return if new_query_values.nil?\n\n        unless new_query_values.is_a?(Array)\n          unless new_query_values.respond_to?(:to_hash)\n            raise TypeError,\n                  \"Can't convert #{new_query_values.class} into Hash.\"\n          end\n          new_query_values = new_query_values.to_hash\n          new_query_values = new_query_values.inject([]) do |object, (key, value)|\n            key = key.to_s if key.is_a?(::Symbol) || key.nil?\n            if value.is_a?(Array) && value.empty?\n              object << [key.to_s + '[]']\n            elsif value.is_a?(Array)\n              value.each { |v| object << [key.to_s + '[]', v] }\n            elsif value.is_a?(Hash)\n              value.each { |k, v| object << [\"#{key.to_s}[#{k}]\", v]}\n            else\n              object << [key.to_s, value]\n            end\n            object\n          end\n          # Useful default for OAuth and caching.\n          # Only to be used for non-Array inputs. Arrays should preserve order.","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/bblimke/webmock/blob/b187df8827e1f08a1684a8ddc0a5050dbd449c16/lib/webmock/util/query_mapper.rb#L167-L203","documentation":"values_to_query serializes a Hash, an Array of [key, value] pairs, or anything responding to to_hash back into a query string; TypeError is raised for anything else (String, Integer, arbitrary object). nil is a documented short-circuit (returns nil), but an already-serialized query string is NOT accepted - this method is the inverse of query_to_values.","triggerScenarios":"WebMock::Util::QueryMapper.values_to_query('a=1&b=2') (passing a query string where a Hash is required); passing an Integer, Symbol, or a Struct/Data object that lacks to_hash; adapters or helpers feeding serialized strings from config into the mapper during add_query_params or build_request_signature.","commonSituations":"Role confusion between query_to_values (parses strings) and values_to_query (serializes hashes); params round-tripped through JSON ending up as Strings; query strings received from one API handed straight to the mapper to re-serialize.","solutions":["Pass a Hash ({ 'a' => '1', 'b' => '2' }) or an Array of [key, value] pairs","If you already have a query string, parse it first with query_to_values and pass the resulting Hash","Call .to_h on duck-typed objects at the boundary before handing them over"],"exampleFix":"// before\nquery = WebMock::Util::QueryMapper.values_to_query('a=1&b=2')\n# => TypeError: Can't convert String into Hash.\n\n// after\nquery = WebMock::Util::QueryMapper.values_to_query({ 'a' => '1', 'b' => '2' })\n# => a=1&b=2","handlingStrategy":"type-guard","validationCode":"values = { 'a' => '1', 'b' => '2' } # a Hash, not the string 'a=1&b=2'\nraise TypeError, 'values_to_query expects a Hash or Array of pairs' unless values.is_a?(Hash)\nquery = WebMock::Util::QueryMapper.values_to_query(values)","typeGuard":"def query_values_input?(value)\n  value.is_a?(Hash) || value.is_a?(Array) || value.respond_to?(:to_hash)\nend","tryCatchPattern":null,"preventionTips":["Remember the direction: query_to_values parses strings, values_to_query serializes Hashes","Convert duck-typed objects with to_h at the boundary","Never feed a serialized query string back into values_to_query"],"tags":["webmock","ruby","typeerror","query-string","argument-type"],"backgroundTag":"invalid-argument-type","analyzedSha":"b187df8827e1f08a1684a8ddc0a5050dbd449c16","analyzedAt":"2026-08-23T02:55:22.028Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}