Skip to content

Commit 64ff7a4

Browse files
authored
Merge pull request #46 from excid3/oj-to-json
Switch Oj to JSON gem
2 parents afcb44a + 37481b4 commit 64ff7a4

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

lib/typesense/api_call.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'faraday'
4-
require 'oj'
4+
require 'json'
55

66
module Typesense
77
class ApiCall
@@ -81,7 +81,7 @@ def perform_request(method, endpoint, query_parameters: nil, body_parameters: ni
8181
req.params = query_parameters unless query_parameters.nil?
8282
unless body_parameters.nil?
8383
body = body_parameters
84-
body = Oj.dump(body_parameters, mode: :compat) if headers['Content-Type'] == 'application/json'
84+
body = JSON.dump(body_parameters) if headers['Content-Type'] == 'application/json'
8585
req.body = body
8686
end
8787
end
@@ -90,7 +90,7 @@ def perform_request(method, endpoint, query_parameters: nil, body_parameters: ni
9090
@logger.debug "Request #{method}:#{uri_for(endpoint, node)} to Node #{node[:index]} was successfully made (at the network layer). response.status was #{response.status}."
9191

9292
parsed_response = if response.headers && (response.headers['content-type'] || '').include?('application/json')
93-
Oj.load(response.body, mode: :compat)
93+
JSON.parse(response.body)
9494
else
9595
response.body
9696
end

lib/typesense/documents.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'oj'
3+
require 'json'
44

55
module Typesense
66
class Documents
@@ -36,7 +36,7 @@ def create_many(documents, options = {})
3636
# @param [Array,String] documents An array of document hashes or a JSONL string of documents.
3737
def import(documents, options = {})
3838
documents_in_jsonl_format = if documents.is_a?(Array)
39-
documents.map { |document| Oj.dump(document, mode: :compat) }.join("\n")
39+
documents.map { |document| JSON.dump(document) }.join("\n")
4040
else
4141
documents
4242
end
@@ -51,8 +51,8 @@ def import(documents, options = {})
5151

5252
if documents.is_a?(Array)
5353
results_in_jsonl_format.split("\n").map do |r|
54-
Oj.load(r)
55-
rescue Oj::ParseError => e
54+
JSON.parse(r)
55+
rescue JSON::ParserError => e
5656
{
5757
'success' => false,
5858
'exception' => e.class.name,

lib/typesense/stemming_dictionaries.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def initialize(api_call)
1111

1212
def upsert(dict_id, words_and_roots_combinations)
1313
words_and_roots_combinations_in_jsonl = if words_and_roots_combinations.is_a?(Array)
14-
words_and_roots_combinations.map { |combo| Oj.dump(combo, mode: :compat) }.join("\n")
14+
words_and_roots_combinations.map { |combo| JSON.dump(combo) }.join("\n")
1515
else
1616
words_and_roots_combinations
1717
end
@@ -25,7 +25,7 @@ def upsert(dict_id, words_and_roots_combinations)
2525
)
2626

2727
if words_and_roots_combinations.is_a?(Array)
28-
result_in_jsonl.split("\n").map { |r| Oj.load(r) }
28+
result_in_jsonl.split("\n").map { |r| JSON.parse(r) }
2929
else
3030
result_in_jsonl
3131
end

typesense.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ Gem::Specification.new do |spec|
2828

2929
spec.add_dependency 'base64', '~> 0.2.0'
3030
spec.add_dependency 'faraday', '~> 2.8'
31-
spec.add_dependency 'oj', '~> 3.16'
31+
spec.add_dependency 'json', '~> 2.9'
3232
spec.metadata['rubygems_mfa_required'] = 'true'
3333
end

0 commit comments

Comments
 (0)