[ruby/json] Deprecate JSON.fast_generate

https://github.com/ruby/json/commit/6508455d82
This commit is contained in:
Jean Boussier 2025-03-27 09:54:51 +01:00 committed by Hiroshi SHIBATA
parent 589713bcb5
commit 2b9a9300ac
Notes: git 2025-03-28 03:45:15 +00:00
2 changed files with 4 additions and 33 deletions

View File

@ -74,16 +74,6 @@ module JSON
$VERBOSE = old $VERBOSE = old
end end
def create_fast_state
State.new(
:indent => '',
:space => '',
:object_nl => "",
:array_nl => "",
:max_nesting => false
)
end
def create_pretty_state def create_pretty_state
State.new( State.new(
:indent => ' ', :indent => ' ',
@ -368,12 +358,12 @@ module JSON
# # Raises SystemStackError (stack level too deep): # # Raises SystemStackError (stack level too deep):
# JSON.fast_generate(a) # JSON.fast_generate(a)
def fast_generate(obj, opts = nil) def fast_generate(obj, opts = nil)
if State === opts if RUBY_VERSION >= "3.0"
state = opts warn "JSON.fast_generate is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated
else else
state = JSON.create_fast_state.configure(opts) warn "JSON.fast_generate is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1
end end
state.generate(obj) generate(obj, opts)
end end
# :call-seq: # :call-seq:

View File

@ -237,25 +237,6 @@ class JSONGeneratorTest < Test::Unit::TestCase
}.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s }) }.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s })
end end
def test_fast_state
state = JSON.create_fast_state
assert_equal({
:allow_nan => false,
:array_nl => "",
:as_json => false,
:ascii_only => false,
:buffer_initial_length => 1024,
:depth => 0,
:script_safe => false,
:strict => false,
:indent => "",
:max_nesting => 0,
:object_nl => "",
:space => "",
:space_before => "",
}.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s })
end
def test_allow_nan def test_allow_nan
error = assert_raise(GeneratorError) { generate([JSON::NaN]) } error = assert_raise(GeneratorError) { generate([JSON::NaN]) }
assert_same JSON::NaN, error.invalid_object assert_same JSON::NaN, error.invalid_object