Skip to content

Commit a67519c

Browse files
feat: allow all valid JSON types to be encoded (#119)
1 parent 4fa584a commit a67519c

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/finch_api/internal/util.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class << self
6161
# @return [Boolean]
6262
def primitive?(input)
6363
case input
64-
in true | false | Integer | Float | Symbol | String
64+
in true | false | Numeric | Symbol | String
6565
true
6666
else
6767
false
@@ -504,7 +504,7 @@ class << self
504504
def encode_content(headers, body)
505505
content_type = headers["content-type"]
506506
case [content_type, body]
507-
in [%r{^application/(?:vnd\.api\+)?json}, Hash | Array]
507+
in [%r{^application/(?:vnd\.api\+)?json}, _] unless body.nil?
508508
[headers, JSON.fast_generate(body)]
509509
in [%r{^application/(?:x-)?jsonl}, Enumerable]
510510
[headers, body.lazy.map { JSON.fast_generate(_1) }]
@@ -516,6 +516,8 @@ def encode_content(headers, body)
516516
[headers, body.tap(&:rewind)]
517517
in [_, StringIO]
518518
[headers, body.string]
519+
in [_, Symbol | Numeric]
520+
[headers, body.to_s]
519521
else
520522
[headers, body]
521523
end

0 commit comments

Comments
 (0)