Skip to content

Commit a8a80e3

Browse files
committed
Fix compatibility with json 2.14.0+
1 parent 4c39e96 commit a8a80e3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

activesupport/lib/active_support/json/encoding.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ class JSONGemCoderEncoder # :nodoc:
147147
json_value = value.as_json
148148
# Handle objects returning self from as_json
149149
if json_value.equal?(value)
150-
next ::JSON::Fragment.new(::JSON.generate(json_value))
150+
if JSON_NATIVE_TYPES.include?(json_value.class)
151+
# If the callback is invoked for a native type,
152+
# it means it is hash keys, e.g. { 1 => true }
153+
next json_value.to_s
154+
else
155+
next ::JSON::Fragment.new(::JSON.generate(json_value))
156+
end
151157
end
152158
# Handle objects not returning JSON-native types from as_json
153159
count = 5

0 commit comments

Comments
 (0)