multi_json 1.20.1-java → 1.21.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ require "oj"
4
4
  require_relative "../adapter"
5
5
  require_relative "oj_common"
6
6
 
7
- module MultiJson
7
+ module MultiJSON
8
8
  # Namespace for JSON adapter implementations
9
9
  #
10
10
  # Each adapter wraps a specific JSON library and provides a consistent
@@ -14,7 +14,7 @@ module MultiJson
14
14
  class Oj < Adapter
15
15
  include OjCommon
16
16
 
17
- defaults :load, mode: :strict, symbolize_keys: false
17
+ defaults :load, mode: :strict, symbolize_names: false
18
18
  defaults :dump, mode: :compat, time_format: :ruby, use_to_json: true
19
19
 
20
20
  # In certain cases the Oj gem may throw a ``JSON::ParserError``
@@ -69,10 +69,10 @@ module MultiJson
69
69
 
70
70
  private
71
71
 
72
- # Translate ``:symbolize_keys`` into Oj's ``:symbol_keys``
72
+ # Translate ``:symbolize_names`` into Oj's ``:symbol_keys``
73
73
  #
74
74
  # Returns a new hash without mutating the input.
75
- # ``:symbol_keys`` is always set (true or false) so MultiJson's
75
+ # ``:symbol_keys`` is always set (true or false) so MultiJSON's
76
76
  # behavior is independent of any global ``Oj.default_options``
77
77
  # the host application may have set. The input is the cached hash
78
78
  # returned from {Adapter.merged_load_options}, so in-place edits
@@ -80,9 +80,9 @@ module MultiJson
80
80
  #
81
81
  # @api private
82
82
  # @param options [Hash] merged load options
83
- # @return [Hash] options with ``:symbolize_keys`` translated
83
+ # @return [Hash] options with ``:symbolize_names`` translated
84
84
  def translate_load_options(options)
85
- options.except(:symbolize_keys).merge(symbol_keys: options[:symbolize_keys] == true)
85
+ options.except(:symbolize_names).merge(symbol_keys: options[:symbolize_names] == true)
86
86
  end
87
87
  end
88
88
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MultiJson
3
+ module MultiJSON
4
4
  module Adapters
5
5
  # Shared functionality for the Oj adapter
6
6
  #
@@ -3,7 +3,7 @@
3
3
  require "yajl"
4
4
  require_relative "../adapter"
5
5
 
6
- module MultiJson
6
+ module MultiJSON
7
7
  module Adapters
8
8
  # Use the Yajl-Ruby library to dump/load.
9
9
  class Yajl < Adapter
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MultiJson
4
- # Catalog of process-wide mutexes used to serialize MultiJson's lazy
3
+ module MultiJSON
4
+ # Catalog of process-wide mutexes used to serialize MultiJSON's lazy
5
5
  # initializers and adapter swaps. Each mutex protects a distinct
6
6
  # piece of mutable state. Callers go through {.synchronize} rather
7
7
  # than touching the mutex constants directly so the constants
@@ -15,10 +15,10 @@ module MultiJson
15
15
  # instance. The names are documented inline so callers can find
16
16
  # what each mutex protects without leaving this file.
17
17
  MUTEXES = {
18
- # Guards the {DEPRECATION_WARNINGS_SHOWN} set in `MultiJson` so the
18
+ # Guards the {DEPRECATION_WARNINGS_SHOWN} set in `MultiJSON` so the
19
19
  # check-then-add pair in `warn_deprecation_once` doesn't race.
20
20
  deprecation_warnings: Mutex.new,
21
- # Guards the process-wide `@adapter` swap in `MultiJson.use` so two
21
+ # Guards the process-wide `@adapter` swap in `MultiJSON.use` so two
22
22
  # threads can't interleave their `OptionsCache.reset` and adapter
23
23
  # assignment.
24
24
  adapter: Mutex.new,
@@ -28,10 +28,10 @@ module MultiJson
28
28
  # warning fires at most once.
29
29
  default_adapter: Mutex.new,
30
30
  # Guards the lazy `default_load_options` / `default_dump_options`
31
- # initializers in `MultiJson::Options`.
31
+ # initializers in `MultiJSON::Options`.
32
32
  default_options: Mutex.new,
33
33
  # Guards the lazy dump-delegate resolution in
34
- # `MultiJson::Adapters::FastJsonparser`.
34
+ # `MultiJSON::Adapters::FastJsonparser`.
35
35
  dump_delegate: Mutex.new
36
36
  }.freeze
37
37
  private_constant :MUTEXES
@@ -49,7 +49,7 @@ module MultiJson
49
49
  # @return [Object] the block's return value
50
50
  # @raise [KeyError] when ``name`` does not match a known mutex
51
51
  # @example
52
- # MultiJson::Concurrency.synchronize(:adapter) { ... }
52
+ # MultiJSON::Concurrency.synchronize(:adapter) { ... }
53
53
  def self.synchronize(name, &)
54
54
  MUTEXES.fetch(name).synchronize(&)
55
55
  end
@@ -4,11 +4,11 @@
4
4
  #
5
5
  # Each method here emits a one-time deprecation warning on first call and
6
6
  # delegates to its current-API counterpart. The whole file is loaded by
7
- # {MultiJson} so the deprecation surface stays out of the main module
7
+ # {MultiJSON} so the deprecation surface stays out of the main module
8
8
  # definition.
9
9
  #
10
10
  # @api private
11
- module MultiJson
11
+ module MultiJSON
12
12
  class << self
13
13
  private
14
14
 
@@ -17,17 +17,18 @@ module MultiJson
17
17
  # The generated singleton method emits a one-time deprecation
18
18
  # warning naming the replacement, then forwards all positional and
19
19
  # keyword arguments plus any block to ``replacement``. Used for the
20
- # ``decode`` / ``encode`` / ``engine*`` / ``with_engine`` /
21
- # ``default_engine`` aliases that are scheduled for removal in v2.0.
20
+ # ``load`` / ``dump`` / ``decode`` / ``encode`` / ``engine*`` /
21
+ # ``with_engine`` / ``default_engine`` aliases that are scheduled
22
+ # for removal in v2.0.
22
23
  #
23
24
  # @api private
24
25
  # @param name [Symbol] deprecated method name
25
26
  # @param replacement [Symbol] current-API method to delegate to
26
27
  # @return [Symbol] the defined method name
27
28
  # @example
28
- # deprecate_alias :decode, :load
29
+ # deprecate_alias :load, :parse
29
30
  def deprecate_alias(name, replacement)
30
- message = "MultiJson.#{name} is deprecated and will be removed in v2.0. Use MultiJson.#{replacement} instead."
31
+ message = "MultiJSON.#{name} is deprecated and will be removed in v2.0. Use MultiJSON.#{replacement} instead."
31
32
  define_singleton_method(name) do |*args, **kwargs, &block|
32
33
  warn_deprecation_once(name, message)
33
34
  public_send(replacement, *args, **kwargs, &block)
@@ -40,8 +41,8 @@ module MultiJson
40
41
  # whose body fans out to multiple replacement methods, and for the
41
42
  # ``cached_options`` / ``reset_cached_options!`` no-op stubs that
42
43
  # have no current-API counterpart at all. The block runs in its
43
- # own lexical ``self``, which is the ``MultiJson`` module since
44
- # every call site sits inside ``module MultiJson`` below.
44
+ # own lexical ``self``, which is the ``MultiJSON`` module since
45
+ # every call site sits inside ``module MultiJSON`` below.
45
46
  #
46
47
  # @api private
47
48
  # @param name [Symbol] deprecated method name
@@ -58,8 +59,10 @@ module MultiJson
58
59
  end
59
60
  end
60
61
 
61
- deprecate_alias :decode, :load
62
- deprecate_alias :encode, :dump
62
+ deprecate_alias :load, :parse
63
+ deprecate_alias :dump, :generate
64
+ deprecate_alias :decode, :parse
65
+ deprecate_alias :encode, :generate
63
66
  deprecate_alias :engine, :adapter
64
67
  deprecate_alias :engine=, :adapter=
65
68
  deprecate_alias :default_engine, :default_adapter
@@ -67,18 +70,18 @@ module MultiJson
67
70
 
68
71
  deprecate_method(
69
72
  :default_options=,
70
- "MultiJson.default_options setter is deprecated\n" \
71
- "Use MultiJson.load_options and MultiJson.dump_options instead"
72
- ) { |value| self.load_options = self.dump_options = value }
73
+ "MultiJSON.default_options setter is deprecated\n" \
74
+ "Use MultiJSON.parse_options and MultiJSON.generate_options instead"
75
+ ) { |value| self.parse_options = self.generate_options = value }
73
76
 
74
77
  deprecate_method(
75
78
  :default_options,
76
- "MultiJson.default_options is deprecated\n" \
77
- "Use MultiJson.load_options or MultiJson.dump_options instead"
78
- ) { load_options }
79
+ "MultiJSON.default_options is deprecated\n" \
80
+ "Use MultiJSON.parse_options or MultiJSON.generate_options instead"
81
+ ) { parse_options }
79
82
 
80
83
  %i[cached_options reset_cached_options!].each do |name|
81
- deprecate_method(name, "MultiJson.#{name} method is deprecated and no longer used.") { nil }
84
+ deprecate_method(name, "MultiJSON.#{name} method is deprecated and no longer used.") { nil }
82
85
  end
83
86
 
84
87
  private
@@ -86,25 +89,25 @@ module MultiJson
86
89
  # Instance-method delegate for the deprecated default_options setter
87
90
  #
88
91
  # @api private
89
- # @deprecated Use {MultiJson.load_options=} and {MultiJson.dump_options=} instead
92
+ # @deprecated Use {MultiJSON.load_options=} and {MultiJSON.dump_options=} instead
90
93
  # @param value [Hash] options hash
91
94
  # @return [Hash] the options hash
92
95
  # @example
93
- # class Foo; include MultiJson; end
96
+ # class Foo; include MultiJSON; end
94
97
  # Foo.new.send(:default_options=, symbolize_keys: true)
95
98
  def default_options=(value)
96
- MultiJson.default_options = value
99
+ MultiJSON.default_options = value
97
100
  end
98
101
 
99
102
  # Instance-method delegate for the deprecated default_options getter
100
103
  #
101
104
  # @api private
102
- # @deprecated Use {MultiJson.load_options} or {MultiJson.dump_options} instead
105
+ # @deprecated Use {MultiJSON.load_options} or {MultiJSON.dump_options} instead
103
106
  # @return [Hash] the current load options
104
107
  # @example
105
- # class Foo; include MultiJson; end
108
+ # class Foo; include MultiJSON; end
106
109
  # Foo.new.send(:default_options)
107
110
  def default_options
108
- MultiJson.default_options
111
+ MultiJSON.default_options
109
112
  end
110
113
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MultiJson
4
- # Mixin providing configurable load/dump options
3
+ module MultiJSON
4
+ # Mixin providing configurable parse/generate options
5
5
  #
6
6
  # Supports static hashes or dynamic callables (procs/lambdas).
7
- # Extended by both MultiJson (global options) and Adapter classes.
7
+ # Extended by both MultiJSON (global options) and Adapter classes.
8
8
  #
9
9
  # @api private
10
10
  module Options
@@ -15,71 +15,145 @@ module MultiJson
15
15
  # because the `#:` cast only applies to method-call results.
16
16
  EMPTY_OPTIONS = Hash.new.freeze #: options # rubocop:disable Style/EmptyLiteral
17
17
 
18
- # Set options for load operations
18
+ # Set options for parse operations
19
19
  #
20
20
  # @api public
21
21
  # @param options [Hash, Proc] options hash or callable
22
22
  # @return [Hash, Proc] the options
23
23
  # @example
24
- # MultiJson.load_options = {symbolize_keys: true}
25
- def load_options=(options)
24
+ # MultiJSON.parse_options = {symbolize_keys: true}
25
+ def parse_options=(options)
26
26
  OptionsCache.reset
27
- @load_options = options
27
+ @parse_options = options
28
28
  end
29
29
 
30
- # Set options for dump operations
30
+ # Set options for generate operations
31
31
  #
32
32
  # @api public
33
33
  # @param options [Hash, Proc] options hash or callable
34
34
  # @return [Hash, Proc] the options
35
35
  # @example
36
- # MultiJson.dump_options = {pretty: true}
37
- def dump_options=(options)
36
+ # MultiJSON.generate_options = {pretty: true}
37
+ def generate_options=(options)
38
38
  OptionsCache.reset
39
- @dump_options = options
39
+ @generate_options = options
40
40
  end
41
41
 
42
- # Get options for load operations
42
+ # Get options for parse operations
43
43
  #
44
- # When `@load_options` is a callable (proc/lambda), it's invoked
44
+ # When `@parse_options` is a callable (proc/lambda), it's invoked
45
45
  # with `args` as positional arguments — typically the merged
46
- # options hash from `Adapter.merged_load_options`. When it's a
46
+ # options hash from `Adapter.merged_parse_options`. When it's a
47
47
  # plain hash, `args` is ignored.
48
48
  #
49
49
  # @api public
50
50
  # @param args [Array<Object>] forwarded to the callable, ignored otherwise
51
51
  # @return [Hash] resolved options hash
52
52
  # @example
53
- # MultiJson.load_options #=> {}
53
+ # MultiJSON.parse_options #=> {}
54
+ def parse_options(*args)
55
+ resolve_options(@parse_options, *args) || default_parse_options
56
+ end
57
+
58
+ # Get options for generate operations
59
+ #
60
+ # @api public
61
+ # @param args [Array<Object>] forwarded to the callable, ignored otherwise
62
+ # @return [Hash] resolved options hash
63
+ # @example
64
+ # MultiJSON.generate_options #=> {}
65
+ def generate_options(*args)
66
+ resolve_options(@generate_options, *args) || default_generate_options
67
+ end
68
+
69
+ # Get default parse options
70
+ #
71
+ # @api private
72
+ # @return [Hash] frozen empty hash
73
+ def default_parse_options
74
+ Concurrency.synchronize(:default_options) { @default_parse_options ||= EMPTY_OPTIONS }
75
+ end
76
+
77
+ # Get default generate options
78
+ #
79
+ # @api private
80
+ # @return [Hash] frozen empty hash
81
+ def default_generate_options
82
+ Concurrency.synchronize(:default_options) { @default_generate_options ||= EMPTY_OPTIONS }
83
+ end
84
+
85
+ # Set options for parse operations
86
+ #
87
+ # @api public
88
+ # @deprecated Use {#parse_options=} instead. Will be removed in v2.0.
89
+ # @param options [Hash, Proc] options hash or callable
90
+ # @return [Hash, Proc] the options
91
+ # @example
92
+ # MultiJSON.load_options = {symbolize_keys: true}
93
+ def load_options=(options)
94
+ MultiJSON.warn_deprecation_once(:load_options=,
95
+ "MultiJSON.load_options= is deprecated and will be removed in v2.0. Use MultiJSON.parse_options= instead.")
96
+ self.parse_options = options
97
+ end
98
+
99
+ # Set options for generate operations
100
+ #
101
+ # @api public
102
+ # @deprecated Use {#generate_options=} instead. Will be removed in v2.0.
103
+ # @param options [Hash, Proc] options hash or callable
104
+ # @return [Hash, Proc] the options
105
+ # @example
106
+ # MultiJSON.dump_options = {pretty: true}
107
+ def dump_options=(options)
108
+ MultiJSON.warn_deprecation_once(:dump_options=,
109
+ "MultiJSON.dump_options= is deprecated and will be removed in v2.0. Use MultiJSON.generate_options= instead.")
110
+ self.generate_options = options
111
+ end
112
+
113
+ # Get options for parse operations
114
+ #
115
+ # @api public
116
+ # @deprecated Use {#parse_options} instead. Will be removed in v2.0.
117
+ # @param args [Array<Object>] forwarded to the callable, ignored otherwise
118
+ # @return [Hash] resolved options hash
119
+ # @example
120
+ # MultiJSON.load_options #=> {}
54
121
  def load_options(*args)
55
- resolve_options(@load_options, *args) || default_load_options
122
+ MultiJSON.warn_deprecation_once(:load_options,
123
+ "MultiJSON.load_options is deprecated and will be removed in v2.0. Use MultiJSON.parse_options instead.")
124
+ parse_options(*args)
56
125
  end
57
126
 
58
- # Get options for dump operations
127
+ # Get options for generate operations
59
128
  #
60
129
  # @api public
130
+ # @deprecated Use {#generate_options} instead. Will be removed in v2.0.
61
131
  # @param args [Array<Object>] forwarded to the callable, ignored otherwise
62
132
  # @return [Hash] resolved options hash
63
133
  # @example
64
- # MultiJson.dump_options #=> {}
134
+ # MultiJSON.dump_options #=> {}
65
135
  def dump_options(*args)
66
- resolve_options(@dump_options, *args) || default_dump_options
136
+ MultiJSON.warn_deprecation_once(:dump_options,
137
+ "MultiJSON.dump_options is deprecated and will be removed in v2.0. Use MultiJSON.generate_options instead.")
138
+ generate_options(*args)
67
139
  end
68
140
 
69
- # Get default load options
141
+ # Get default parse options
70
142
  #
71
143
  # @api private
144
+ # @deprecated Use {#default_parse_options} instead. Will be removed in v2.0.
72
145
  # @return [Hash] frozen empty hash
73
146
  def default_load_options
74
- Concurrency.synchronize(:default_options) { @default_load_options ||= EMPTY_OPTIONS }
147
+ default_parse_options
75
148
  end
76
149
 
77
- # Get default dump options
150
+ # Get default generate options
78
151
  #
79
152
  # @api private
153
+ # @deprecated Use {#default_generate_options} instead. Will be removed in v2.0.
80
154
  # @return [Hash] frozen empty hash
81
155
  def default_dump_options
82
- Concurrency.synchronize(:default_options) { @default_dump_options ||= EMPTY_OPTIONS }
156
+ default_generate_options
83
157
  end
84
158
 
85
159
  private
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "concurrent/map"
4
4
 
5
- module MultiJson
5
+ module MultiJSON
6
6
  module OptionsCache
7
7
  # Thread-safe cache store backed by Concurrent::Map
8
8
  #
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MultiJson
3
+ module MultiJSON
4
4
  # Thread-safe bounded cache for merged options hashes
5
5
  #
6
6
  # Caches are separated for load and dump operations. Each cache is
@@ -39,8 +39,8 @@ module MultiJson
39
39
  # @api public
40
40
  # @return [Integer] current cache size limit
41
41
  # @example
42
- # MultiJson::OptionsCache.max_cache_size = 5000
43
- # MultiJson::OptionsCache.max_cache_size #=> 5000
42
+ # MultiJSON::OptionsCache.max_cache_size = 5000
43
+ # MultiJSON::OptionsCache.max_cache_size #=> 5000
44
44
  attr_reader :max_cache_size
45
45
 
46
46
  # Set the maximum number of entries per cache store
@@ -50,7 +50,7 @@ module MultiJson
50
50
  # @return [Integer] the validated value
51
51
  # @raise [ArgumentError] when value is not a positive Integer
52
52
  # @example
53
- # MultiJson::OptionsCache.max_cache_size = 5000
53
+ # MultiJSON::OptionsCache.max_cache_size = 5000
54
54
  def max_cache_size=(value)
55
55
  raise ArgumentError, "max_cache_size must be a positive Integer, got #{value.inspect}" unless Integer === value && value.positive? # rubocop:disable Style/CaseEquality
56
56
 
@@ -71,7 +71,7 @@ module MultiJson
71
71
  end
72
72
  end
73
73
 
74
- module MultiJson
74
+ module MultiJSON
75
75
  module OptionsCache
76
76
  # Dynamic require path so MRI (mutex_store) and JRuby
77
77
  # (concurrent_store) execute the same physical line, avoiding a
@@ -82,5 +82,5 @@ module MultiJson
82
82
  end
83
83
  end
84
84
 
85
- require_relative "options_cache/#{MultiJson::OptionsCache.send(:const_get, :BACKENDS).fetch(RUBY_ENGINE, "mutex_store")}"
86
- MultiJson::OptionsCache.reset
85
+ require_relative "options_cache/#{MultiJSON::OptionsCache.send(:const_get, :BACKENDS).fetch(RUBY_ENGINE, "mutex_store")}"
86
+ MultiJSON::OptionsCache.reset
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MultiJson
3
+ module MultiJSON
4
4
  # Raised when JSON parsing fails
5
5
  #
6
6
  # Wraps the underlying adapter's parse error with the original input
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MultiJson
4
- # Version information for MultiJson
3
+ module MultiJSON
4
+ # Version information for MultiJSON
5
5
  #
6
6
  # @api private
7
7
  class Version
8
8
  # Major version number
9
- MAJOR = 1 unless defined? MultiJson::Version::MAJOR
9
+ MAJOR = 1 unless defined? MultiJSON::Version::MAJOR
10
10
  # Minor version number
11
- MINOR = 20 unless defined? MultiJson::Version::MINOR
11
+ MINOR = 21 unless defined? MultiJSON::Version::MINOR
12
12
  # Patch version number
13
- PATCH = 1 unless defined? MultiJson::Version::PATCH
13
+ PATCH = 0 unless defined? MultiJSON::Version::PATCH
14
14
  # Pre-release version suffix
15
- PRE = nil unless defined? MultiJson::Version::PRE
15
+ PRE = nil unless defined? MultiJSON::Version::PRE
16
16
 
17
17
  class << self
18
18
  # Return the version string