From 26bc510daa0360b773e2b0c8c4d5828b2b259c0a Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Sun, 3 Aug 2025 21:21:27 -0500 Subject: [PATCH 1/2] Switch Oj to JSON gem --- lib/typesense/api_call.rb | 6 +++--- lib/typesense/documents.rb | 8 ++++---- lib/typesense/stemming_dictionaries.rb | 4 ++-- typesense.gemspec | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/typesense/api_call.rb b/lib/typesense/api_call.rb index 5812667..4c11a91 100644 --- a/lib/typesense/api_call.rb +++ b/lib/typesense/api_call.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'faraday' -require 'oj' +require 'json' module Typesense class ApiCall @@ -81,7 +81,7 @@ def perform_request(method, endpoint, query_parameters: nil, body_parameters: ni req.params = query_parameters unless query_parameters.nil? unless body_parameters.nil? body = body_parameters - body = Oj.dump(body_parameters, mode: :compat) if headers['Content-Type'] == 'application/json' + body = JSON.dump(body_parameters) if headers['Content-Type'] == 'application/json' req.body = body end end @@ -90,7 +90,7 @@ def perform_request(method, endpoint, query_parameters: nil, body_parameters: ni @logger.debug "Request #{method}:#{uri_for(endpoint, node)} to Node #{node[:index]} was successfully made (at the network layer). response.status was #{response.status}." parsed_response = if response.headers && (response.headers['content-type'] || '').include?('application/json') - Oj.load(response.body, mode: :compat) + JSON.parse(response.body) else response.body end diff --git a/lib/typesense/documents.rb b/lib/typesense/documents.rb index fdc6530..8595062 100644 --- a/lib/typesense/documents.rb +++ b/lib/typesense/documents.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'oj' +require 'json' module Typesense class Documents @@ -36,7 +36,7 @@ def create_many(documents, options = {}) # @param [Array,String] documents An array of document hashes or a JSONL string of documents. def import(documents, options = {}) documents_in_jsonl_format = if documents.is_a?(Array) - documents.map { |document| Oj.dump(document, mode: :compat) }.join("\n") + documents.map { |document| JSON.dump(document) }.join("\n") else documents end @@ -51,8 +51,8 @@ def import(documents, options = {}) if documents.is_a?(Array) results_in_jsonl_format.split("\n").map do |r| - Oj.load(r) - rescue Oj::ParseError => e + JSON.parse(r) + rescue JSON::ParserError => e { 'success' => false, 'exception' => e.class.name, diff --git a/lib/typesense/stemming_dictionaries.rb b/lib/typesense/stemming_dictionaries.rb index e71702d..4dca5e3 100644 --- a/lib/typesense/stemming_dictionaries.rb +++ b/lib/typesense/stemming_dictionaries.rb @@ -11,7 +11,7 @@ def initialize(api_call) def upsert(dict_id, words_and_roots_combinations) words_and_roots_combinations_in_jsonl = if words_and_roots_combinations.is_a?(Array) - words_and_roots_combinations.map { |combo| Oj.dump(combo, mode: :compat) }.join("\n") + words_and_roots_combinations.map { |combo| JSON.dump(combo) }.join("\n") else words_and_roots_combinations end @@ -25,7 +25,7 @@ def upsert(dict_id, words_and_roots_combinations) ) if words_and_roots_combinations.is_a?(Array) - result_in_jsonl.split("\n").map { |r| Oj.load(r) } + result_in_jsonl.split("\n").map { |r| JSON.parse(r) } else result_in_jsonl end diff --git a/typesense.gemspec b/typesense.gemspec index e4e139f..947e29a 100644 --- a/typesense.gemspec +++ b/typesense.gemspec @@ -28,6 +28,6 @@ Gem::Specification.new do |spec| spec.add_dependency 'base64', '~> 0.2.0' spec.add_dependency 'faraday', '~> 2.8' - spec.add_dependency 'oj', '~> 3.16' + spec.add_dependency 'json', '~> 2.3' spec.metadata['rubygems_mfa_required'] = 'true' end From 37481b4cad59771f1171f1b0013ef664789ed070 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Mon, 11 Aug 2025 15:53:06 -0500 Subject: [PATCH 2/2] Update typesense.gemspec --- typesense.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typesense.gemspec b/typesense.gemspec index 947e29a..f585e92 100644 --- a/typesense.gemspec +++ b/typesense.gemspec @@ -28,6 +28,6 @@ Gem::Specification.new do |spec| spec.add_dependency 'base64', '~> 0.2.0' spec.add_dependency 'faraday', '~> 2.8' - spec.add_dependency 'json', '~> 2.3' + spec.add_dependency 'json', '~> 2.9' spec.metadata['rubygems_mfa_required'] = 'true' end