@@ -70,9 +70,6 @@ def generator=(generator) # :nodoc:
7070 end
7171 self . state = generator ::State
7272 const_set :State , self . state
73- const_set :SAFE_STATE_PROTOTYPE , State . new # for JRuby
74- const_set :FAST_STATE_PROTOTYPE , create_fast_state
75- const_set :PRETTY_STATE_PROTOTYPE , create_pretty_state
7673 ensure
7774 $VERBOSE = old
7875 end
@@ -101,6 +98,29 @@ def create_pretty_state
10198
10299 # Sets or Returns the JSON generator state class that is used by JSON.
103100 attr_accessor :state
101+
102+ private
103+
104+ def deprecated_singleton_attr_accessor ( *attrs )
105+ args = RUBY_VERSION >= "3.0" ? ", category: :deprecated" : ""
106+ attrs . each do |attr |
107+ singleton_class . class_eval <<~RUBY
108+ def #{ attr }
109+ warn "JSON.#{ attr } is deprecated and will be removed in json 3.0.0", uplevel: 1 #{ args }
110+ @#{ attr }
111+ end
112+
113+ def #{ attr } =(val)
114+ warn "JSON.#{ attr } = is deprecated and will be removed in json 3.0.0", uplevel: 1 #{ args }
115+ @#{ attr } = val
116+ end
117+
118+ def _#{ attr }
119+ @#{ attr }
120+ end
121+ RUBY
122+ end
123+ end
104124 end
105125
106126 # Sets create identifier, which is used to decide if the _json_create_
@@ -334,13 +354,6 @@ def generate(obj, opts = nil)
334354 end
335355 end
336356
337- # :stopdoc:
338- # I want to deprecate these later, so I'll first be silent about them, and
339- # later delete them.
340- alias unparse generate
341- module_function :unparse
342- # :startdoc:
343-
344357 # :call-seq:
345358 # JSON.fast_generate(obj, opts) -> new_string
346359 #
@@ -363,12 +376,6 @@ def fast_generate(obj, opts = nil)
363376 state . generate ( obj )
364377 end
365378
366- # :stopdoc:
367- # I want to deprecate these later, so I'll first be silent about them, and later delete them.
368- alias fast_unparse fast_generate
369- module_function :fast_unparse
370- # :startdoc:
371-
372379 # :call-seq:
373380 # JSON.pretty_generate(obj, opts = nil) -> new_string
374381 #
@@ -418,34 +425,26 @@ def pretty_generate(obj, opts = nil)
418425 state . generate ( obj )
419426 end
420427
421- # :stopdoc:
422- # I want to deprecate these later, so I'll first be silent about them, and later delete them.
423- alias pretty_unparse pretty_generate
424- module_function :pretty_unparse
425- # :startdoc:
428+ # Sets or returns default options for the JSON.unsafe_load method.
429+ # Initially:
430+ # opts = JSON.load_default_options
431+ # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
432+ deprecated_singleton_attr_accessor :unsafe_load_default_options
426433
427- class << self
428- # Sets or returns default options for the JSON.unsafe_load method.
429- # Initially:
430- # opts = JSON.load_default_options
431- # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
432- attr_accessor :unsafe_load_default_options
433- end
434- self . unsafe_load_default_options = {
434+ @unsafe_load_default_options = {
435435 :max_nesting => false ,
436436 :allow_nan => true ,
437437 :allow_blank => true ,
438438 :create_additions => true ,
439439 }
440440
441- class << self
442- # Sets or returns default options for the JSON.load method.
443- # Initially:
444- # opts = JSON.load_default_options
445- # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
446- attr_accessor :load_default_options
447- end
448- self . load_default_options = {
441+ # Sets or returns default options for the JSON.load method.
442+ # Initially:
443+ # opts = JSON.load_default_options
444+ # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
445+ deprecated_singleton_attr_accessor :load_default_options
446+
447+ @load_default_options = {
449448 :allow_nan => true ,
450449 :allow_blank => true ,
451450 :create_additions => nil ,
@@ -581,9 +580,9 @@ class << self
581580 #
582581 def unsafe_load ( source , proc = nil , options = nil )
583582 opts = if options . nil?
584- unsafe_load_default_options
583+ _unsafe_load_default_options
585584 else
586- unsafe_load_default_options . merge ( options )
585+ _unsafe_load_default_options . merge ( options )
587586 end
588587
589588 unless source . is_a? ( String )
@@ -741,9 +740,9 @@ def unsafe_load(source, proc = nil, options = nil)
741740 #
742741 def load ( source , proc = nil , options = nil )
743742 opts = if options . nil?
744- load_default_options
743+ _load_default_options
745744 else
746- load_default_options . merge ( options )
745+ _load_default_options . merge ( options )
747746 end
748747
749748 unless source . is_a? ( String )
@@ -778,17 +777,12 @@ def recurse_proc(result, &proc) # :nodoc:
778777 end
779778 end
780779
781- alias restore load
782- module_function :restore
783-
784- class << self
785- # Sets or returns the default options for the JSON.dump method.
786- # Initially:
787- # opts = JSON.dump_default_options
788- # opts # => {:max_nesting=>false, :allow_nan=>true}
789- attr_accessor :dump_default_options
790- end
791- self . dump_default_options = {
780+ # Sets or returns the default options for the JSON.dump method.
781+ # Initially:
782+ # opts = JSON.dump_default_options
783+ # opts # => {:max_nesting=>false, :allow_nan=>true}
784+ deprecated_singleton_attr_accessor :dump_default_options
785+ @dump_default_options = {
792786 :max_nesting => false ,
793787 :allow_nan => true ,
794788 }
@@ -841,7 +835,7 @@ def dump(obj, anIO = nil, limit = nil, kwargs = nil)
841835 end
842836 end
843837
844- opts = JSON . dump_default_options
838+ opts = JSON . _dump_default_options
845839 opts = opts . merge ( :max_nesting => limit ) if limit
846840 opts = opts . merge ( kwargs ) if kwargs
847841
0 commit comments